首页 \ 问答 \ socket.io客户端重新连接超时(socket.io client reconnect timeout)

socket.io客户端重新连接超时(socket.io client reconnect timeout)

我使用socket.io和node.js,我喜欢这个解决方案。 我注意到的唯一问题是断开连接和重新连接。

这些是我目前的设置:

  'connect timeout': 1000,
  'reconnect': true,
  'reconnection delay': 300,
  'max reconnection attempts': 10000,
  'force new connection':true

我注意到,如果我停下来并启动node.js进程,客户端将连接正常并且很快,但是如果服务器处于脱机状态几分钟,则客户端不会重新连接或需要很长时间(非用户友好)时间至。

我想问问是否有任何我错过了或可能添加到socket.io配置,以保持客户端轮询重新连接。

我知道'重新连接延迟':

重新连接延迟默认为500毫秒

启动重新连接的初始超时,每次进行新的重新连接尝试时都会使用指数退避算法来增加。

但指数效应对用户不太友好。 是否有一种方法可以每隔X个时间周期检查一次连接 - 例如:5秒。

如果没有,我想我可以写一些客户端JS来检查连接并尝试重新连接,如果需要的话,但它会很好,如果socket.io客户端提供了这一点。

谢谢


I'm using socket.io with node.js and I like the solution. The only issue I notice is around a disconnection and reconnection.

These are my current settings:

  'connect timeout': 1000,
  'reconnect': true,
  'reconnection delay': 300,
  'max reconnection attempts': 10000,
  'force new connection':true

I notice if I stop and start the node.js process the client connects back fine and quickly, however if the server is offline for a couple of minutes the client either never reconnects or takes a very long (non-user friendly) amount of time to.

I wanted to ask if there is anything I've missed or could add to the socket.io configuration to keep the client polling for a reconnection.

I know 'reconnection delay':

reconnection delay defaults to 500 ms

The initial timeout to start a reconnect, this is increased using an exponential back off algorithm each time a new reconnection attempt has been made.

But the exponential effect its not very user friendly. Is there a way to keep checking for a connection every X period of time - eg: 5 seconds.

If not I guess I can write some client side JS to check the connect and attempt reconnections if needed but it would be nice if the socket.io client offered this.

thx


原文:https://stackoverflow.com/questions/20558290
更新时间:2022-03-19 11:03

最满意答案

不知何故,我怀疑你的驱动程序是否支持FrameBufferObject扩展,如果它不提供着色器但它值得一试。 那么这不是你想要的,你可能不得不首先使用glTexEnv或稍微聪明一点然后我,但是它应用了一个掩码和图像,但实际上并没有添加alpha值:

import pyglet
from pyglet.gl import *

window = pyglet.window.Window()
image = pyglet.resource.image('pic.jpg')
mask = pyglet.resource.image('mask.jpg')
createdtex=False;
imagetex = 0


@window.event
def on_draw():
    window.clear()
    global createdtex
    texfrmbuf =(GLuint*1)()
    global imagetex
    if createdtex!=True:
        imagetex = image.get_texture()
        glEnable(GL_BLEND)
        glBlendFunc(GL_ZERO, GL_SRC_COLOR)
        glGenFramebuffersEXT(1,texfrmbuf)
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,texfrmbuf[0])
        glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT, imagetex.target,imagetex.id,0)
        mask.blit(0,0)
        glFlush()
        glDisable(GL_BLEND)
        glDeleteFramebuffersEXT(1,texfrmbuf)
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,0)
        createdtex=True

    imagetex.blit(0,0)

pyglet.app.run()

Somehow I doubt that your driver supports the FrameBufferObject extension if it doesn't provide shaders but it's worth a shot. Well this isn't quite what you want so, you'll probably have to use glTexEnv after all or be a little more clever about it then me but this applies a mask to and image but doesn't actually add the alpha value:

import pyglet
from pyglet.gl import *

window = pyglet.window.Window()
image = pyglet.resource.image('pic.jpg')
mask = pyglet.resource.image('mask.jpg')
createdtex=False;
imagetex = 0


@window.event
def on_draw():
    window.clear()
    global createdtex
    texfrmbuf =(GLuint*1)()
    global imagetex
    if createdtex!=True:
        imagetex = image.get_texture()
        glEnable(GL_BLEND)
        glBlendFunc(GL_ZERO, GL_SRC_COLOR)
        glGenFramebuffersEXT(1,texfrmbuf)
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,texfrmbuf[0])
        glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT, imagetex.target,imagetex.id,0)
        mask.blit(0,0)
        glFlush()
        glDisable(GL_BLEND)
        glDeleteFramebuffersEXT(1,texfrmbuf)
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,0)
        createdtex=True

    imagetex.blit(0,0)

pyglet.app.run()

相关问答

更多
  • 正如所提到的,glTexEnv是要走的路。 要替换纹理的RGB组件并保持其alpha不变,可以尝试如下所示(此代码使用红色作为替换颜色): glColor4f( 1.0f, 0.0f, 0.0f, 1.0f ); glActiveTexture( GL_TEXTURE_0 ); glEnable( GL_TEXTURE_2D ); glBindTexture(GL_TEXTURE_2D, spriteTexture); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_M ...
  • 我只猜测: 绘制第一个纹理可以在RGB和alpha通道中显示204(0.8 * 255)。 当您第二次绘制时(启用GL_BLEND,我推测),您将获得浅灰色204 RGB和80%alpha,这将为您提供中灰色。 解决方案:使用glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)并预乘你的颜色。 I'm only guessing: Drawing the first texture gives you 204 (0.8 * 255) in the RGB and alpha ...
  • 好的,如果我正确理解你的问题,诀窍是BLEND_RGBA_MULT标志。 我决定自己测试一下,因为我很好奇。 我从这张图片开始: 我用白色想要图像展示的图像,以及我希望遮盖的透明度。 我甚至给了它不同程度的透明度,看看我是否可以得到模糊掩蔽。 ^^^你可能看不到图像,因为它是透明的白色,但它在那里。 您可以右键单击并下载它。 我加载了两个图像,确保使用convert_alpha() : background = pygame.image.load("leaves.png").convert_alpha() ...
  • 不知何故,我怀疑你的驱动程序是否支持FrameBufferObject扩展,如果它不提供着色器但它值得一试。 那么这不是你想要的,你可能不得不首先使用glTexEnv或稍微聪明一点然后我,但是它应用了一个掩码和图像,但实际上并没有添加alpha值: import pyglet from pyglet.gl import * window = pyglet.window.Window() image = pyglet.resource.image('pic.jpg') mask = pyglet.resou ...
  • 我认为你使用错误的混合模式。 如果您没有更改默认混合模式,则需要: glEnable (GL_BLEND); // Enable blending. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Setup blending function. 我认为在你的情况下,纹理不与背景融合,它简单地取代背景。 I think you use wrong blending mode. If you did not change default blend ...
  • 您的纹理是GL_RGBA,因此每个纹素都有不同的alpha值。 如果要更改用于渲染的alpha值,我可以考虑以下方法: 更改纹理alpha值(不确定是否表示您不想这样做)。 使用glColor4f更改顶点的alpha值。 它将乘以纹理值。 您可能需要使用glEnable(GL_COLOR_MATERIAL)和/或glColorMaterial() 。 使用顶点着色器更改顶点Alpha值。 它将乘以纹理值。 使用片段着色器可以动态更改采样的纹理值。 使用两个纹理阶段并将它们相乘。 第二个将具有修改的alpha ...
  • 我不知道为什么它不适合你。 我刚刚将文件更改为 而输出是 我改变的比较: I don't know why it isn't working for you. I just changed the file to and the output was Comparison of what I changed:
  • 您很可能只需要启用GL ALPHA混合物。 from pyglet.gl import * glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 但首先,您的代码无法运行。 主要是因为你没有声明window.event函数来处理通常渲染事物的on_draw 。 其次,你永远不会清除你的窗户(这将导致一团糟)。 这是代码的最小工作示例: import pyglet import pyglet.clock window = ...
  • SDL_CreateRGBSurfaceFrom depth参数是以the depth of the surface in bits 。 sizeof(unsigned char) * BYTES_PER_PIXEL是3(假设BYTES_PER_PIXEL是3,正如你所说的那样是24 bpp),它应该是24; 乘以一个字节的位数。 至于第二部分 - 是的,会有。 取决于许多因素,包括CPU和GPU硬件以及GL驱动程序。 最好的测试方法是编写两个版本。 然而,由于在屏幕上绘制单个四边形并不是昂贵的操作,因此您 ...
  • 如果您只想按原样显示单个颜色通道,那么glColorMask就足够了。 假设您只想显示红色通道,您可以这样做: glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); 如果要切换2个颜色通道或应用灰度效果,则通过着色器运行它可能是最简单的方法: uniform sampler2D frame; in vec2 uv; out vec4 fragColor; void main() { vec4 color = texture(frame, uv ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)