How to handle request from client TCP socket and client Websocket with same port?
This would take a bit of creative work because you'd have to wait until the first data arrives on a newly connected socket in order to discern what type of connection it must be. Both start with an incoming TCP connection.
The webSocket connections then follow the initial TCP connection with an http request that requests a protocol upgrade to the webSocket protocol. You can examine the first data that arrives on the newly connected TCP socket and check to see if the first data on the socket is indeed an http request of that form. If it is, then it's an incoming webSocket connection.
If not, then it must be your regular TCP connection. In either case, once you identified which type of connection it must be, you'd pass the initial data on to the appropriate handler for that type of connection so it could take over processing of that socket.
A somewhat similar model is used to allow an http server and a webSocket server to share the same port. It's a bit easier for them since both protocols start with an http request, but the idea is the same in that when a webSocket server is sharing an http server, it examines the incoming request to see if it looks like the start of a webSocket connection (an http request with the upgrade
header). If so, it passes the request to the webSocket handling code. If not, it treats it as a normal incoming http request and passes it to the http request handling code.
You can see how the initial webSocket connection looks here: How does WebSockets server architecture work? and here: node js net sockets + websocket without socket.io. Both will show you the form of the initial http request that initiates all webSocket connections.