Open eduardoseitz opened 1 year ago
The server is running with no errors.
I ran into a similar problem and the solution is quite simple. You have to use your host's IP address rather than localhost
-- this goes for all clients (i.e different devices or scripts). For clarity, look up your IPv4 address (it should be something like 192.168.X.X
) and replace localhost with the IP address which should result in looking something more like "ws://192.168.X.X:3000"
.
Also note that this is only on local networks (which should be on the same router!).
Here's a stackoverflow answer that helped me reach to this answer and may be additional use if you run into more errors. https://stackoverflow.com/questions/21410435/connect-websocket-server-by-lan-ip-address
@Steve-Morales sadly that didn't solve it. I have the same issue. I have a Node.js server and I am able to connect from terminal, local website, remote website but I simply can't connect with Unity. I tried localhost/127/192/hosts and nothing worked for Unity.
I even created new URL in /etc/hosts/
and used Docker for more separation. Nothing.
string address = "unity-sockets.com:8080";
// this connects fine
UnityWebRequest webReq = new($"http://{address}", "GET");
webReq.SendWebRequest();
// this won't even ping the server
websocket = new WebSocket($"ws://{address}");
websocket.Connect();
I tried to create a local https/wss server but it won't connect due to certificate issue. Still, the socket did not even ping the server.
Maybe your server have https redirection. Try to open http://localhost:3000 in chrome and view F12 network
` public class WebSocketController : MonoBehaviour { WebSocket websocket;
if !UNITY_WEBGL || UNITY_EDITOR
endif
`