I'm using node.js with the socket.io module. I have a need to disconnect a websocket client on occasion. Can I do this forcibly from the server, or does the server have to "ask" the client to disconnect?
Note. From the server I've tried socket.end() which works from the client, but not on the server side.
Related
I am currently building a WebSocket client and would like to test basic connectivity (connect, disconnect, reconnect).
I am looking for a WebSocket server tool/app that I can run on my desktop and test my client against it without coding it myself, is there a thing like it out there?
I have created a php websocket server, and a php websocket client, the websocket client communicate with the server using JSON format, each message means an operation to handle by the websocket server.
when running both the client and the server in localhost I can reach about 35 operations/sconds, and the same results when running both client and websocket server on the production server, but running client in locahost (my machine) with production websocket server (remote) that only results in 5 operations/seconds.
What could be the reason behind that bad performance when using remote websocket server?
Solved by changing websocket client app logic (sending messages asynchronously instead of synchronously), by using that approach we have increased the score to more than 100 operations/s.
Credits to Jérôme Richard (See the question comments)
I understand that RSocket connection is bidirectional.
How long can a client be connected to a server via RSocket before the connection is terminated?
And if the connection actually does terminate, how does it get reconnected if the server wants to send something to the client?
Minutes, Days or Weeks?
It's dependent on your use. Server to Server with lifetime of those servers. Or Mobile connecting to a backend with sticky routing and resumption.
However while the connection is bi-directional, the client must always initiate the (re-)connection.
https://github.com/rsocket/rsocket-java/blob/d903e9635a159285b6943ea93156c31aa406ba5d/rsocket-examples/src/main/java/io/rsocket/examples/transport/tcp/resume/ResumeFileTransfer.java
wss://www.mysite.ca/socket.io/?EIO=3&transport=websocket
This is how chrome webdevoloper tools shows the request url of a socket io.
I am trying to understand more about EIO=3&transport=websocket .
I have to invoke the url from an API tool
These are query parameters that the socket.io client sends to the socket.io server as part of the initial connection request.
EIO=3, I believe, is the version number of the engine.io sub-system in socket.io. If the server is not compatible with this version number, it will likely fail the attempt to connect.
transport=websocket says that socket.io wants to use the websocket protocol as the eventual transport. socket.io has several different transports it supports including web polling and a flash-based protocol.
To connect to socket.io server, you will need a full-fledged socket.io client. You can't make a socket.io connection by just sending a URL from a tool to the server. There's a lot more involved than that in establishing a working socket.io connection.
My websocket server listens on port 8080 with no proxy.
Most of the time I'm getting requests with the Upgrade Websocket header and it works fine.
Sometimes I'm getting HTTP CONNECT requests.
Is this a valid request?
Does it means that there is a proxy server between the client and the server?
How my server is suppose to respond to the CONNECT request?
Thanks
You are getting CONNECT requests because you are likely to have configured your browser to use a proxy. If you directed your browser to use port 8080 on your local IP address, it will assume there is a proxy and that means when you ask for a secure connection, the browser leads with CONNECT.
You will need to add support for SSL/TLS tunnelling to your server to deal with this.