-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No explanation or working code example for WebSocketClient? How are we supposed to use this? Is this a bug? #108695
Comments
Tagging subscribers to this area: @dotnet/ncl |
I was able to get a basic case working with:
Looks like need to set the send third argument to "true" or it is never deemed finished on the server side. Will have to look at other issues beyond that. |
I agree that the WebSocket conceptual docs seem incomplete in this regard. Can you please open an issue in the docs repo https://github.com/dotnet/docs/ to add the full working example for sending and receiving messages?
The "third argument" is the
The way your localhost server reacts to the incomplete messages is up to the server implementation. I assume the server only replied after the message was received in its full. That's why you never got a response (I see that you were able to troubleshoot that yourself). |
Thanks. I shared my working basic code example (so far) and posted the request here: I would like to see it "fixed" to add other types of events like disconnection, message received, message sent, etc. and some way for handling re-connection attempts. I explained all that over there. |
Description
The only documentation I see on WebSocketClient is here: https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/websockets
No working code is provided for setting up even the simplest WebSocket client configuration.
The best example I can find is here: https://stackoverflow.com/a/68284475/10305478
Which is also gibberish since it appears to continuously send random data to the server. I have tried my own configuration based on that as follows, but it does not work. I can send data but nothing is ever received back:
Class:
In this case, I am able to successfully connect, and send. But nothing is ever received. I get to starting the while loop, but nothing is received by it and it never leaves this loop.
I can easily receive using WebSocketSharp (but this is abandoned) and Websocket.Client (which is a wrapper apparently of WebSocketClient), and I can also receive from Firefox console, so there is nothing wrong with the localhost server, but WebSocketClient just won't receive anything.
Is there any working documentation anywhere on the Internet for how we are supposed to implement WebSocketClient for a basic web socket client (ie. send text messages, receive messages back)?
Or what is wrong here? Is this a bug?
Reproduction Steps
Copy and paste the above code into a project with a localhost server configured to reply to "ping".
Expected behavior
Should get something back.
Actual behavior
No message is returned.
Regression?
No response
Known Workarounds
No response
Configuration
.NET 8 Windows
Other information
No response
The text was updated successfully, but these errors were encountered: