4

I'm trying to connect to a web socket server on localhost:9222 using this C# code:

var ws = new ClientWebSocket();
var uri = new Uri("ws://localhost:9222/X/Y/Z", UriKind.Absolute);
await ws.ConnectAsync(uri, CancellationToken.None);

On that last line, I'm getting Unable to connect to the remote server, with inner exception The remote server returned an error: (404) Not Found..

However, I have this JavaScript that connects to the same WebSocket:

var ws = new WebSocket("ws://localhost:9222/X/Y/Z");

And it works great in both IE and Chrome.

I'm not using any proxies.

Is there something I've missed to configure in the C# code?

How can I debug this?

Update:

Using WebSocket4Net instead of the .NET 4.5 ClientWebSocket, I'm getting HTTP 1.1 500: Internal Server Error. However, I'm not sure how I can debug this either.

Markus Johnsson
  • 3,949
  • 23
  • 30
  • Maybe you are missing some header information, use `Fiddler` to check what browser is sending – sallushan Jun 01 '14 at 16:58
  • I've tried fiddler, always have it in the background, but fiddler was no help this time.. It only shows sockets as "Tunnel to localhost". However, Chrome nicely debugs sockets and, you are right, it has to do with headers. I'm about to figure this one out. Will write up an answer when I do. – Markus Johnsson Jun 01 '14 at 20:20
  • Did you able to connect using .NET 4.5 ClientWebSocket? – cdev Jun 19 '14 at 10:19
  • Nope, I think that the server I'm connecting to is not implementing the standard correctly. However, I've used a regular System.Net.Socket to connect as a proof of concept. I might go that way even though it means that I will have to implement the handshaking manually. – Markus Johnsson Jun 19 '14 at 10:43

0 Answers0