© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
2 replies
Strikeeaglechase

❔ Websocket connection fails, however a javascript websocket can connect to server fine

I am using
System.Net.WebSockets
System.Net.WebSockets
to create a websocket client to a websocket server I am running. The following code is used to create the websocket
Debug.Log("Setting up websocket");
client = new ClientWebSocket();
await client.ConnectAsync(new Uri("ws://192.168.68.93:8001/ws"), System.Threading.CancellationToken.None);
Debug.Log($"Socket status: {client.State}");
Debug.Log("Setting up websocket");
client = new ClientWebSocket();
await client.ConnectAsync(new Uri("ws://192.168.68.93:8001/ws"), System.Threading.CancellationToken.None);
Debug.Log($"Socket status: {client.State}");

The following error is produced:
System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server ---> System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server ---> System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.


The confusing part to me, the following code in javascript works perfectly fine
const ws = new WebSocket("ws://192.168.68.93:8001/ws")
const ws = new WebSocket("ws://192.168.68.93:8001/ws")

And if I log the messages I receive, they are what I expect/work perfectly fine.

What would cause a JS websocket to work, but not a C# one?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ SignalR Websocket Connection failed
C#CC# / help
4y ago
How to check bandwidth of websocket connection?
C#CC# / help
3y ago
Specify timeout for websocket connection
C#CC# / help
2y ago
❔ [.NET 6 application] - WebSocket connection to 'wss://...' failed.
C#CC# / help
3y ago