Hi, I would like to know if it is possible to connect to a TCP server from a WebGL build with a TCP client?
No you need websockets which is why they offer it
I tend to say: Yes, but you have to use WebSockets.
WebSockets uses TCP because UDP is not available in browsers. This then requires the endpoint (server) to also use WebSockets. Itās really more a technicality.
As it was already mentioned, no, you can not use the TCPClient in a WebGL build as it builds on top of the Socket class. Custom socket connections of any kind arenāt supported in the security sandbox of a browser. The closest thing to a socket connection you can use are WebSockets. Since they are designed to specifically āupgradeā a normal HTTP connection, itās the only thing that is supported in browsers. Because HTTP connections are already guarded against cross domain access, the same rules apply to them. So the server may need to implement CORS if hosted on a separate domain / port, otherwise the browser will refuse to connect.
Though it should be mentioned that you need to use a native javascript implementation of websockets. So you can not use a websocket library that is written in C# that under the hood is using a TCPClient or Socket as those can not be used at all. So make sure the websocket library is actually using the native javascript websocket when build for WebGL.