Socket.IO

SocketIO + Flask Detect Disconnect

时光毁灭记忆、已成空白 提交于 2020-08-10 00:44:17
问题 I had a different question here, but realized it simplifies to this: How do you detect when a client disconnects (closes their page or clicks a link) from a page (in other words, the socket connection closes)? I want to make a chat app with an updating user list, and I’m using Flask on Python. When the user connects, the browser sends a socket.emit() with an event and username passed in order to tell the server a new user exists, after which the server will message all clients with socket

SocketIO + Flask Detect Disconnect

大城市里の小女人 提交于 2020-08-10 00:42:45
问题 I had a different question here, but realized it simplifies to this: How do you detect when a client disconnects (closes their page or clicks a link) from a page (in other words, the socket connection closes)? I want to make a chat app with an updating user list, and I’m using Flask on Python. When the user connects, the browser sends a socket.emit() with an event and username passed in order to tell the server a new user exists, after which the server will message all clients with socket

Socket.io sends two messages

一笑奈何 提交于 2020-08-08 06:29:07
问题 I'm trying to setup socket.io and here is part of my server.js const app = require('express')(); const http = require('http').Server(app); const io = require('socket.io')(http, { path: '/websocket', origins:'*:*' }); io.on('connection', (socket) => { socket.send('Hi'); socket.on('message', (message) => { console.log(message); socket.emit('hello', `New: ${message}`); }); console.log('a user connected'); }); http.listen(3030, function(){ console.log('listening on *:3030'); }); and my simple

Socket.io Uncaught TypeError: Cannot read property 'apply' of undefined

柔情痞子 提交于 2020-08-05 07:54:05
问题 A particular event doesn’t work in my program where I am using socket.io. The rest works fine. This is where the problem occurs: First html file: socket.on('connect', () => {socket.emit('phone', 'phone');}); Server file: io.on('connection', function(socket){ io.on('phone', function(socket, data){ io.emit('stuurbedrijfsnaam', 'stuurbedrijfsnaam'); }); }); 2nd html file: socket.on('stuurbedrijfsnaam', function(socket){ socket.emit('stuurbedrijfsnaam',bedrijfsnaam) }) This is the full error

什么是长轮询,Websocket,服务器发送事件(SSE)和Comet?

一曲冷凌霜 提交于 2020-08-05 02:34:05
问题: I have tried reading some articles, but I am not very clear on the concepts yet. 我已经尝试阅读一些文章,但是我对这些概念还不太清楚。 Would someone like to take a shot at explaining to me what these technologies are: 有人想向我解释一下这些技术是什么吗? Long Polling 长轮询 Server-Sent Events 服务器发送的事件 Websockets 网络套接字 Comet 彗星 One thing that I came across every time was, the server keeps a connection open and pushes data to the client. 我每次遇到的一件事是,服务器保持打开连接并将数据推送到客户端。 How is the connection kept open, and how does the client get the pushed data? 连接如何保持打开状态,客户端如何获取推送的数据? (How does the client use the data, maybe some code might help?)

深入浅出FE(十二)浅析websocket

微笑、不失礼 提交于 2020-08-04 14:40:37
目录 一、为什么要有websocket? 二、关于websocket 三、websocket的请求响应过程 四、为什么WebSocket连接可以实现全双工通信而HTTP连接不行呢? 五、WebSocket 的用法 六、服务端的实现 七、websocket的踩坑 一、为什么要有websocket? websocket的出现是为了弥补http协议服务端无法向客户端主动推送消息。所以以前实现这种场景都是通过用轮询或者Comet。轮询是指浏览器通过JavaScript启动一个定时器,然后以固定的间隔给服务器发请求,询问服务器有没有新消息。这个机制的缺点一是实时性不够,二是频繁的请求会给服务器带来极大的压力。 Comet本质上也是轮询,但是在没有消息的情况下,服务器先拖一段时间,等到有消息了再回复。这个机制暂时地解决了实时性问题,但是它带来了新的问题:以多线程模式运行的服务器会让大部分线程大部分时间都处于挂起状态,极大地浪费服务器资源。另外,一个HTTP连接在长时间没有数据传输的情况下,链路上的任何一个网关都可能关闭这个连接,而网关是我们不可控的,这就要求Comet连接必须定期发一些ping数据表示连接“正常工作”。 二、关于websocket WebSocket 协议在2008年诞生,2011年成为国际标准。所有浏览器都已经支持。 它的最大特点就是,服务器可以主动向客户端推送信息

ReactJS + Socket.IO - Best way to handle socket connection

假如想象 提交于 2020-08-02 08:13:41
问题 I'm trying to make a ReactJS realtime application with Node and Socket.IO, but I'm having a hard time figuring out the best way to handle my socket connection on the clientside. I have multiple React components that all need some information from the server, and preferrably in realtime via the socket connection. But when importing the socket.io-client dependency and making the connection to the server in different files, I get multiple connections to the server, which doesn't really seem that

Socket.io local network not connecting

白昼怎懂夜的黑 提交于 2020-08-02 04:19:13
问题 Okay, I have the following setup: https://i.stack.imgur.com/4T9SX.jpg ( If image below is too small ) The problem is that Computer 2 can not connect with socket.io to computer 1. Yes i included socket.io in computer 2: Any ideas as to why Computer 2 cannot connect to computer 1 with socket.io whilst ping can? Extra information: - Socket.io version 1.4.5 - Both computers are windows 10 - Computer 2 javascript is in Phonegap - Computer 2 connects via wi-fi, computer 1 via ethernet Greetings

socket.io sets cross-site cookie without same-site attribute

依然范特西╮ 提交于 2020-08-01 06:38:55
问题 I have a socket.io application and recently I got this warning: A cookie associated with a cross-site resource at URL was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure . You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.`

开源在线聊天应用-Fiora

╄→尐↘猪︶ㄣ 提交于 2020-07-27 22:03:14
Fiora是国人开发的一款在线聊天开源应用。基于node.js, mongodb, socket.io和react编写。遵守MIT开源协议。 主要功能特色: 好友, 群组, 私聊, 群聊 文本, 图片, 代码, url等多种类型消息 贴吧表情, 滑稽表情, 搜索表情包 桌面通知, 声音提醒, 消息语音朗读 自定义桌面背景, 主题颜色, 文本颜色 查看在线用户, @功能 管理员 关小黑屋 撤回消息 给用户打标签 重置用户密码 查看用户 ip GitHub 仓库挂件 WordPress 插件 yinxin630 / fiora An interesting chat application power by socket.io, koa, mongodb and react https://fiora.suisuijiang.com/ 3,890 765 Download ZIP 相关文件下载地址 本地直接下载 来源: oschina 链接: https://my.oschina.net/u/4397293/blog/4302042