I’m know WebGL Only using UnityWebRequest or WWW,but I’m no idea.
Original Code:
IPAddress TgtAddress = IPAddress.Parse(m_ServerIPAddress);
IPEndPoint TgtIpEndpoint = new IPEndPoint(TgtAddress, m_ServerPort);
m_Socket = new Socket ( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
IAsyncResult ConnectResult = m_Socket.BeginConnect( TgtIpEndpoint, new AsyncCallback ( ConnectCallback ), m_Socket );
bool IsConnectSuccess = ConnectResult.AsyncWaitHandle.WaitOne( 5000, true );
How to fix on WebGL?
The answer is simple: You can not use manual sockets like this. This is not a Unity limitation but a limitation of the security sandbox of the browser that runs your wen content. Web applications are not allowed to perform arbitrary network connections. The only things available are the usual HTTP requests (keep in mind that you have cross origin restrictions as well) and WebSockets. WebSockets is a protocol that builds on top of HTTP and provides a two-way communication connection. However it works vastly different from normal sockets. You need a WebSocket library in order to use them. Also the server you want to connect to also need to implement a WebSocket server.