Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have 2 clients in asp.net with difference by url:
localhost:port/api/send
and
localhost:port/api/new

I'm using websocket and trying to send the message that "send-client" send (sorry for repetitiveness), but catch an exception
The server returned status code '404' when status code '101' was expected.
when trying to connect to another client uri. Here's my code
using (var socket = new ClientWebSocket())
                {
                    var uri = new Uri("ws://localhost:49350/api/send");
                    var cts = new System.Threading.CancellationTokenSource();
                    await socket.ConnectAsync(uri, cts.Token);
                    if (socket.State == WebSocketState.Open)
                    {
                        ArraySegment<byte> bytesSend = new ArraySegment<byte>(Encoding.UTF8.GetBytes($"{message.Id}+{message.Text}+{message.SentTime}"));
                        await socket.SendAsync(bytesSend, WebSocketMessageType.Text, true, cts.Token);
                    }
                }


What I have tried:

Don't really know what the reason of it. Google doesn't help too
Posted
Updated 15-Jul-20 3:43am

1 solution

Not sure what you mean by
Quote:
when trying to connect to another client uri
but anyway, looking at the code you've got, I take it you've verified the server is running and a netstat -an | more shows 'something' listening on port 49350.

If so, then something on the server side is denying the connection due to perhaps authentication, or maybe the client isnt whitelisted - so the server returns a 404 because the 'handshake' fails
 
Share this answer
 
Comments
triyul22 15-Jul-20 10:12am    
Oh, I just entered wrong port. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900