WebSockets-Sharp Exeption: WebSocketException

Its not the code that is causing error its the mess created by algorithm you have written for the application. The actual error is "The header of a frame cannot be read from the stream" this simply can be caused due to the following issues

Your appliation and server both are sending bulk messages or heavy data at faster rate at the same time to each other. which is well defined and explained here

Solution

You have to optimize your algorithm to meet the following constraints and remove that error

  1. Monitor and Control the data transfer rate to/from the server
  2. Try to wait for the completion of data transfer of one side (Half Duplex)