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
msThe 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
最满意答案
不知何故,我怀疑你的驱动程序是否支持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 ...
-
Pygame - 有没有什么方法可以在面具中进行blit或更新(Pygame - is there any way to only blit or update in a mask)[2023-08-11]
好的,如果我正确理解你的问题,诀窍是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 ...
-
如何在Python / PyGame中增加Alpha掩码的大小?(How can I increase the size of my Alpha mask in Python / PyGame?)[2023-06-11]
我不知道为什么它不适合你。 我刚刚将文件更改为 而输出是 我改变的比较: 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 ...