If you use the socket.io library on the server, then you need to use the socket.io library on the client, because it is a protocol on top of webSocket, so both ends must speak the same language.
webSockets (and socket.io in this case) are designed to share your web server. Thus, any request to connect to the WebSocket server is sent to the same host and port as your web server.
Each webSocket request starts with an HTTP request (thus it is processed by your web server) and this HTTP request as a header in it that asks for an upgrade to the webSocket protocol. When your web server sees this user header, it disables the management of the socket.io library, which then responds that the upgrade to the webSocket protocol is in order, and the socket that started working as an HTTP request now becomes a socket, the application says webSocket / socket .io.
The socket.io library automatically connects to your web server to view these protocol update requests.
On the web page, the socket.io client code for connecting to this would look like this:
<script src="/socket.io/socket.io.js"></script> <script> var socket = io(); socket.on('connect', function() { </script>
The socket.io library will automatically connect to the same host from which the web page appeared. You do not even need to provide a URL.
source share