There is no standard way to make a TCP connection with Javascript code running in a web browser. (See Reply from @Johannes Hahn)
To establish a connection between your client and server, consider the Microsoft SignalR library. It is designed to allow browser-based Javascript to communicate with a C # server. SignalR will use websockets; however, it will continue to work if websites are unavailable if you return to other vehicles. You can also specify transports if you need to prevent attempts to use websites.
The SignalR connection starts as HTTP, and then it advances to the WebSocket connection, if available. WebSocket is the ideal transport for SignalR because it provides the most efficient use of server memory, has the lowest latency and has the most basic features (such as full duplex communication between the client and server), but also has the most stringent requirements: WebSocket requires the server to use Windows Server 2012 or Windows 8 and the .NET Framework 4.5. If these requirements are not met, SignalR will try to use other transports for its connections.
Also, keep in mind that if your Javascript is not running in a web browser, you can make regular network connections. For example, a Javascript application running on Node.js.
source share