Reputation: 87
I need to send image to client whenever it's available in the server. The client is not a browser but some kind of device(linux box) behind NAT (3G network) that will get the image as a file, write it to disk then display it in a screen (no browser here).
I'm new to nodejs and websocket.
Can I use a nodejs as a websocket client in the device and a nodejs as a server? Can you provide an example of using nodejs to execute a websocket client?
In this case, can nodejs detect 3G network loss then resume or restart the websocket?
What happen if connection loss happen while nodejs server is pushing an image to the device nodejs (client)? is there any resume solution?
how about Binary Js to handle file transfer between the 2 nodejs?
Can I do that with some pub/sub mecanism using a MOM like ActiveMQ?
Upvotes: 3
Views: 3226
Reputation: 145052
Socket.io (which is probably what you'll want to use server-side) has a client module that works in node. It handles maintaining a connection to the server.
What you'll probably want to do is not push the image itself over the WebSocket connection. Instead, send a "new image available" notification message over the WebSocket, and when the client receives the message, make a regular HTTP GET
request to the server to download the image.
Since you're making a regular HTTP request, you can use the Range
header if you need to resume an interrupted download.
Upvotes: 3