There is no need to maintain code that implements the websocket protocol. Just wrap the TcpClient stream with a factory method from the System library System.Net.Sockets.WebSocket.CreateFromStream(client.GetStream(), true, null, TimeSpan.FromSeconds(n)) and you get all the functionality for free.