LiveOrDevTrying / WebsocketsSimple

WebsocketsSimple provides an easy-to-use and customizable Websocket Server and Websocket Client. The server is created using a TcpListener and upgrades a successful connection to a WebSocket. The server and client can be used for non-SSL or SSL connections and authentication (including client and server SSL certification validation) is provided for identifying the clients connected to your server. Both client and server are created in .NET Standard and use async await functionality.
Apache License 2.0
21 stars 2 forks source link

Is it possible to send raw bytes? #4

Closed TinkerWorX closed 2 years ago

TinkerWorX commented 2 years ago

As the title asks, is it possible to send raw bytes? I would like to avoid the overhead and allocation of converting everything to strings. On the JavaScript side it is possible to use ArrayBuffer and the different low level array types(DataView, etc) with websockets.

LiveOrDevTrying commented 2 years ago

Looking at the code, probably. I'll write up a fix and comment when its updated.

LiveOrDevTrying commented 2 years ago

Hi @TinkerWorX , This was a good request. I've added in support for sending raw bytes. There is a new overload for SendAsync() in client and server. However, use caution - https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/binaryformatter-serialization-obsolete. Its typically better to send a string of json / xml over sending raw bytes because of the risk of malicious polymorphic serialization / deserialization. Thank you!

TinkerWorX commented 2 years ago

Appreciate the work and the word of caution. Fortunately I'm just using it for a game to stream various state objects with a very limited protocol.