Search code examples
node.jswebsockettcpsocket.iotcpclient

Is it possible to connect to Node.js's net moudle from browser?


i want to make TCP server with Node.js and then connect it from browser without http , express and socket.io moudles. something like what i do in java or c# but this time from browser.


Solution

  • The browser does not contain the capability for Javascript in a regular web page to make a straight TCP socket connection to some server.

    Browser Javascript has access to the following network connection features:

    1. Make an http/https request to an external server.
    2. Make a webSocket connection to an external server.
    3. Use webRTC to communicate with other computers

    In all these cases, you must use the libraries built into the browser in order to initiate connections on these specific protocols.

    There is no capability built into the browser for a plain TCP socket connection. A webSocket (which can only connect to a webSocket server) is probably the closest you can come.