Socket.IO

Remove objects on disconnect socket.io

岁酱吖の 提交于 2020-01-01 02:05:09
问题 I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created. Do these objects just linger forever? Should they be deleted or removed when the client disconnects? Is it even possible to remove an object? I know delete won't work... Thanks - I guess this is more of a general question and any suggestions would be really helpful. Thanks! 回答1: If you don't cleanup, then yes, they will stay there forever since I assume you are making them global. You should cleanup

Remove objects on disconnect socket.io

北城余情 提交于 2020-01-01 02:05:09
问题 I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created. Do these objects just linger forever? Should they be deleted or removed when the client disconnects? Is it even possible to remove an object? I know delete won't work... Thanks - I guess this is more of a general question and any suggestions would be really helpful. Thanks! 回答1: If you don't cleanup, then yes, they will stay there forever since I assume you are making them global. You should cleanup

socket.io handshake return error “Transport unknown”

*爱你&永不变心* 提交于 2019-12-31 11:59:06
问题 I'm trying to use elephant.io to send event from my PHP script to my nodejs server. Performing tests with this library I've noticed that the handshake was not happening as expected. After reading the specs about client-server handshake with socket.io, I've tested a simple handshake request to my nodejs server: POST "http://acme.local:3700/socket.io/1" But this is returning the following JSON message: { "code": 0, "message": "Transport unknown" } I'm not sure if this error is due to the

Sharing binary buffer between Node.js server and Browser

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-31 10:36:23
问题 There is an issue of how to share buffers between node.js and the browser containing binary data. I'm pretty happy with Socket.io as a transport layer but the issue is that there is no porting of the Buffer class for the browser. Not something I can find anyways I've also came across binary.js and I was wondering if there is a good way to combine them having the socket.io as the transport layer and the Binary.js as the data medium. I also saw this question, which is kind of on topic but doesn

how to get socket.id of a connection on client side?

纵然是瞬间 提交于 2019-12-31 08:39:10
问题 Im using the following code in index.js io.on('connection', function(socket){ console.log('a user connected'); console.log(socket.id); }); the above code lets me print the socket.id in console. But when i try to print the socket.id on client side using the following code <script> var socket = io(); var id = socket.io.engine.id; document.write(id); </script> it gives 'null' as output in the browser. 回答1: You should wait for the event connect before accessing the id field: With this parameter,

Developing a mobile chat room, backend use XMPP or WebSocket?

我们两清 提交于 2019-12-31 05:07:34
问题 Some requirements for a mobile chat room: Should be able to work seamlessly with client's frequent connect/disconnect due to the mobile network Bandwidth saving (less overhead) I don't have experience in XMPP, I only have worked with Node.JS server and it is easy to setup and hack the server with JavaScript. But seems XMPP is the defacto standard for chat room, e.g. WhatsApp use them., anyone can share your experience in these two technologies? 回答1: You are kind of asking how can I get to my

Socket.io code 200 Error during WebSocket handshake

萝らか妹 提交于 2019-12-31 04:45:13
问题 I am using socket.io with nodejs and an apache server over it. I am getting a code 200 as response, I know I must get 101 . WebSocket connection to 'wss://SITEABC.com/socket.io/?siteId=site1234567&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Invalid status line The configuration on apache is the folowing: RewriteCond %{HTTP:Upgrade} ^Websocket [NC] RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC] RewriteRule .* ws://localhost:1337/{REQUEST_URI} [P] RewriteCond %{REQUEST

How to use https with letsencrypt, socket.io and node.js?

拈花ヽ惹草 提交于 2019-12-31 04:41:25
问题 Im trying to get https to work with socket.io and node.js. I can connect and all works if I test with a http page. I get this error when I try to load the socket.io.js file. GET https://my ip number:3000/socket.io/socket.io.js net::ERR_INSECURE_RESPONSE Im linking like this <script src="https://my ip number:3000/socket.io/socket.io.js"></script> And my server.js file looks like this var fs = require('fs'); var https = require('https'); var http = require('https'); var express = require(

How to use https with letsencrypt, socket.io and node.js?

佐手、 提交于 2019-12-31 04:41:05
问题 Im trying to get https to work with socket.io and node.js. I can connect and all works if I test with a http page. I get this error when I try to load the socket.io.js file. GET https://my ip number:3000/socket.io/socket.io.js net::ERR_INSECURE_RESPONSE Im linking like this <script src="https://my ip number:3000/socket.io/socket.io.js"></script> And my server.js file looks like this var fs = require('fs'); var https = require('https'); var http = require('https'); var express = require(

Android Emitter.Listener not working

时间秒杀一切 提交于 2019-12-31 03:57:13
问题 I'm making an app with socket IO, it connects correctly to the server, but it doesn't listen to events. Here's part of my code: private Socket mSocket; { try { mSocket = IO.socket(ip+":8000"); } catch (URISyntaxException e) { throw new RuntimeException(e); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ads); mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError); mSocket.on(Socket.EVENT_CONNECT_TIMEOUT,