I have to send data to the server after each minute. While I send the data from the Socket client it gets disconnected with a transport error.
I have increased the limit of maxHttpBufferSize to 1e8, but still, I am facing the same issue. Tried locally, and sent data over size 8 MB it worked and the socket didn't get disconnected. But in production, it is not working.
Related
I am using websocket (mqtt js) to connect to aws iot core.
My keep alive is 10 seconds.
For the first time, the mqtt client is able to connect to aws iot core service without problem, as keep alive is small, i see disconnect from time to time. mqtt js try to reconect and it able to do that as we can see in photo below with the response 101. I can see many logs in cloudWatch for aws iot core [ connect, publish, subscribe ..]
After 12 reconnects, i am receiving 403 as shown below in firfox debug tool.
with response header:
I see nothing in cloudWatch
When i refresh the page, same thing will repeated.
Any idea ?.
The ws package for nodeJS hides incoming ping frames by default and silently responds to them with pong frames.
How can I catch these incoming ping frames and take note of them?
You just listen for a ping event: https://github.com/websockets/ws/blob/master/doc/ws.md#event-ping
The real answer here is RTFM.
You need a Node app for that. The app and your front-end (FE) will have open websockets via which they will communicate.
Conceptually, you run a node server and open a web-socket on it. Then you serve your FE to users. The FE in user's browser opens connection back to the server via the websocket. The server sends/pushes some messages to FE via this open channel, and also the client can send some messages to the app.
The websockets differ from a simple requests in that you can PUSH data to the FE. With simple requests, the FE can only PULL data from the server.
I have small HTTP + WebSocket server hosted on Amazon VPS. Index.html has JS code to connect WebSocket server and exchange data with it. When I connect my server directly using public IP or domain name - everything works fine.
However I don't want this server to be public, so I configured OpenVPN to connect to this server privately.
Sometimes everything works as expected over OpenVPN and when I enter local (inside VPN) servers IP address in my browser (Chrome or Opera) it succesfully loads index.html, connects my WebSocket server and succesfully exchanges data via WebSocket connection.
But sometimes (or some days) 1 second after Websocket connection is established it is closed by browser with error code 1006 and without any description. My script tries to reconnect WebSocket 1 second after this, but result is the same all the time.
I can't figure out why sometimes everything is working and sometimes I can't use WebSocket over OpenVPN for several hours.
Can somebody describe why error 1006 occures when using WebSocket over OpenVPN and how to eliminate it by coding or reconfiguring Chrome, Opera or OpenVPN?
I discovered that problem only occurs when any side of WS connection sends large message.
I guess that if there is some middleware like VPN, firewall or proxy between browser and WebSocket server, then large WS message can exceed some internal packet size or limit of that middleware and it will interrupt the connection between browser and server during message transfer. This unexpected disconnect results to error 1006 in your browser.
If your clients experience unexpected disconnects with error 1006, try to minimize WebSocket message sizes of your API. If you need to send large data amounts then don't send it in one chunk. You better slice it and send multiple short messages.
I made a API server using node.js
My server is connected to a large number of clients.
Because of this, the server's response time is increased.
So Client disconnected before receiving the response
but still processing the server(for client request).
How can I solve this problem?
I'm working on a solution that requires a webpage to print raw data onto a connected printer. One option is to send the data to the printer through a process, running on the same machine as the browser. The process listens on a specific port and forwards the data from the browser to the printer.
Is it possible to send data from a webpage to another listening process using Websockets?
Websockets can send to any port, not just port 80. But unfortunately Websockets don't transport raw data. Before the connection is established, a Websocket handshake is performed, which also includes a 32-bit masking key which is XORed with the data stream from the client. That data-stream is also framed by some additional bytes. Details can be found in the RFC.
This unfortunately means that a Websocket client can not communicate with a service which does not support the Websocket protocol. So you will need a middleware which accepts the users websocket connection, unpacks the data stream and forwards it to the printer.
One such middleware is Websockify.