jchristn / WatsonWebsocket

A simple C# async websocket server and client for reliable transmission and receipt of data
MIT License
277 stars 53 forks source link

String version of SendAsync doesn't send string #107

Closed mawkish00 closed 1 year ago

mawkish00 commented 1 year ago

Hello, and thank you for providing WatsonWebsocket. It's a delight to use it :-) But when i updated from version 2.3.2.5 to 4.0.1, I got problem with my (unchanged) Javascript client. Data was received as a binary blob instead of a string.

The method that I used in WatsonWsServer.cs, on .NET 6.0.11, was: public Task<bool> SendAsync(Guid guid, string data, CancellationToken token = default)

My workaround to get it to work as before was to instead call one of the overloads:

bool success = ws.SendAsync(client.Guid, message).Result;
-->
bool success = ws.SendAsync(
    client.Guid,
    Encoding.UTF8.GetBytes(message),
    System.Net.WebSockets.WebSocketMessageType.Text).Result;

I saw in the history that WebSocketMessageType.Text was used in the old public Task<bool> SendAsync(string ipPort, string data, CancellationToken token = default) so I guess the type was lost by mistake. Thanks!

jchristn commented 1 year ago

Hi @mawkish00 I assume this is server-side? Thanks for letting me know, please try NuGet v4.0.2: https://www.nuget.org/packages/WatsonWebsocket/4.0.2 and reopen if any issues!