Socket.IO

Incorrect state upon hook callback

允我心安 提交于 2020-03-05 03:01:47
问题 I'm writing a chat client using socket.io and react hooks. The message history (chatMessages) when addMessage (upon receiving the message event) is called is incorrect (always an empty array). chatMessages does update (correctly), but on the next call it is empty. There shouldn't be any other variable named chatMessages and messages is in the parent class (the set hook works so I don’t see why the state should be invalid). The state doesn't appear to update again either, so it appears to

socket.io和websockets之间的差异

杀马特。学长 韩版系。学妹 提交于 2020-02-28 06:34:32
node.js中socket.io和websockets之间有什么区别? 它们都是服务器推送技术吗? 我觉得唯一的区别是, socket.io允许我通过指定事件名称来发送/发送消息。 在socket.io的情况下,来自服务器的消息将到达所有客户端,但对于websockets中的相同内容,我被迫保留所有连接的数组并循环通过它以向所有客户端发送消息。 另外,我想知道为什么网络检查员(如Chrome / firebug / fiddler)无法从服务器捕获这些消息(来自socket.io/websocket)? 请澄清一下。 #1楼 它的优点是它简化了#2中描述的WebSockets的使用,并且可能更重要的是,它在浏览器或服务器不支持WebSockets的情况下为其他协议提供故障转移。 我会避免直接使用WebSockets,除非您非常熟悉它们不起作用的环境并且您能够解决这些限制。 这是对WebSockets和Socket.IO的良好读取。 http://davidwalsh.name/websocket #2楼 我将提供反对使用socket.io的论据。 我认为使用socket.io只是因为它有后备不是一个好主意。 让IE8 RIP。 在过去,很多情况下NodeJS的新版本已经破坏了socket.io。 您可以查看这些列表以获取示例... https://github.com

SpringBoot(23) 集成socket.io服务端和客户端实现通信

限于喜欢 提交于 2020-02-27 18:20:53
一、前言 websocket 和 socket.io 区别? websocket 一种让客户端和服务器之间能进行双向实时通信的技术 使用时,虽然主流浏览器都已经支持,但仍然可能有不兼容的情况 适合用于client和基于node搭建的服务端使用 socket.io 将WebSocket、AJAX和其它的通信方式全部封装成了统一的通信接口 使用时,不用担心兼容问题,底层会自动选用最佳的通信方式 适合进行服务端和客户端双向数据通信 w3cschool上对socket.io的描述如下: 本文将实现 基于 springboot2.1.8.RELEASE 集成 netty-socketio : 仿 node.js 实现的 socket.io服务端 集成 socket.io-client : socket.io客户端 实现 服务端 与 客户端 之间的 通信 二、 Java 集成 socket.io 服务端 1、 pom.xml 中引入所需依赖 温馨小提示:这里为了方便将后面需要的客户端 socket.io-client 依赖一起直接引入了哦~ <!-- netty-socketio: 仿`node.js`实现的socket.io服务端 --> <dependency> <groupId>com.corundumstudio.socketio</groupId> <artifactId>netty

How to catch ERR_CONNECTION_REFUSED thrown by browser if server goes down?

牧云@^-^@ 提交于 2020-02-26 08:53:11
问题 I think this question is pretty straightforward, but I haven't found an answer yet in the official Socket.io docs. I have my Socket.io server and client communicating successfully, and when I shut down the server, the client will attempt to reconnect with the server unsuccessfully. This is shown in the Chrome developer's console here: Is there any way to detect this event in the client-side Javscript and react to it some way? I'm thinking I would display a dialog on the page, such as "Sorry,

How to catch ERR_CONNECTION_REFUSED thrown by browser if server goes down?

五迷三道 提交于 2020-02-26 08:52:48
问题 I think this question is pretty straightforward, but I haven't found an answer yet in the official Socket.io docs. I have my Socket.io server and client communicating successfully, and when I shut down the server, the client will attempt to reconnect with the server unsuccessfully. This is shown in the Chrome developer's console here: Is there any way to detect this event in the client-side Javscript and react to it some way? I'm thinking I would display a dialog on the page, such as "Sorry,

socket.io assigning custom socket.id

﹥>﹥吖頭↗ 提交于 2020-02-26 08:32:58
问题 I keep track the list of every users connected in the array. So if there is a new connection, it will check whether the user is already on the list or not, if he was already on the list, then assign their socket.id with the corresponding socket.id on the list, otherwise just add them to the list. It's for preventing same user counted as 2 user while he attempt to do multi-login. Object.keys(client).forEach(function (key) { if (client[key].id == data.id){ is_connected = true; socket.id = key;

socket.io assigning custom socket.id

允我心安 提交于 2020-02-26 08:32:50
问题 I keep track the list of every users connected in the array. So if there is a new connection, it will check whether the user is already on the list or not, if he was already on the list, then assign their socket.id with the corresponding socket.id on the list, otherwise just add them to the list. It's for preventing same user counted as 2 user while he attempt to do multi-login. Object.keys(client).forEach(function (key) { if (client[key].id == data.id){ is_connected = true; socket.id = key;

Is it possible to use UDP with socket.io?

╄→гoц情女王★ 提交于 2020-02-18 06:14:04
问题 I have a game I am working on and I heard that UDP is superior for real-time games. I know that socket.io uses TCP and was wondering if there is some way to switch it to UDP. I tried looking it up but only found posts from around 2012 which said UDP is only experimental in browsers. 回答1: From a standard browser, it is not possible. From a browser client, socket.io uses either the http or the webSocket transport. Both http and webSocket are TCP connections, not UDP connections. So the browser

Is it possible to use UDP with socket.io?

安稳与你 提交于 2020-02-18 06:04:27
问题 I have a game I am working on and I heard that UDP is superior for real-time games. I know that socket.io uses TCP and was wondering if there is some way to switch it to UDP. I tried looking it up but only found posts from around 2012 which said UDP is only experimental in browsers. 回答1: From a standard browser, it is not possible. From a browser client, socket.io uses either the http or the webSocket transport. Both http and webSocket are TCP connections, not UDP connections. So the browser

Is it possible to use UDP with socket.io?

只谈情不闲聊 提交于 2020-02-18 06:04:06
问题 I have a game I am working on and I heard that UDP is superior for real-time games. I know that socket.io uses TCP and was wondering if there is some way to switch it to UDP. I tried looking it up but only found posts from around 2012 which said UDP is only experimental in browsers. 回答1: From a standard browser, it is not possible. From a browser client, socket.io uses either the http or the webSocket transport. Both http and webSocket are TCP connections, not UDP connections. So the browser