TsgcWebSocketServer_HTTPAPI › Events › OnBinary
Fires every time a client sends a binary message and it is received by the server.
public event TsgcWSBinaryEventHandler OnBinary;
// delegate void TsgcWSBinaryEventHandler(TsgcWSConnection Connection, TMemoryStream Data)
—
OnBinary is raised once a full binary payload has been received and buffered from a client. The Data parameter exposes the decoded bytes as a TMemoryStream positioned at 0; read it inside the handler because the stream is owned by the server and becomes invalid after the handler returns. The event runs on the IOCP worker thread that handled the incoming HTTP.SYS WebSocket frame, so marshal to the main thread before touching UI controls. If Options.FragmentedMessages is frgOnlyFragmented the event is not raised and OnFragmented is used instead.
private void OnBinary(TsgcWSConnection Connection, byte[] Bytes)
{
MemoryStream stream = new MemoryStream(Bytes);
pictureBox1.Image = new Bitmap(stream);
}