javascriptnode.jstcpchatreal-time

Node.js Broadcasting Image In Real-time


By using net module (not WebSockets), I want to create a real-time chat application with a simple TCP server. So far, I have been able to implement the text-based chatting system with net module. However, for instance, I cannot write a code that sends image in real-time. By using net module, I want to write a TCP server for real-time image sending. How can I achieve this in Node.js? Can you give me some code to do this task or is there any documentation link for this task? Thanks...

With my TCP server, I have implemented the real-time text-based chat system; however, I also want to learn how I can send image in real-time with net module in Node.js.


Solution

  • Nothing is stopping you from sending an image or any other arbitrary data over TCP.

    You can serialize the image to JSON, and send as text, or send the image as one or more TypedArrays.

    Then reconcontruct the data per your specification on the other side of the socket.