- Home /
WebGL Can't Using Socket.How to fixed?
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?
Answer by Bunny83 · Aug 22, 2019 at 08:39 AM
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.
Answer by thelghome · Oct 25, 2019 at 04:45 AM
You may try FM WebSockets. It supports WebGL build with WebSockets communication.
Asset Store Link: http://u3d.as/1DH3
youtube streaming demo for your reference: https://youtu.be/82_-a7WF3vs
Your answer
Follow this Question
Related Questions
[C#] Sockets on mobile devices 0 Answers
LLAPI vs. pure C#.NET sockets 3 Answers
C# Networking help? 1 Answer
Multiple Cars not working 1 Answer
Unity Twitch chat on WEBGL 0 Answers