This project is read-only.

WebSocket4Net 0.10 Send method fails after automatic reconnect

Sep 21, 2014 at 7:42 PM
I have the problem in the system having WebSocket4Net 0.10 on the client side and SuperWebSocket 0.9 (self-compiled) and SuperSocket 1.6.3 on the server side.
After client sends request with length larger than the MaxRequestLength parameter, the communication is disconnected on the server side. The WebSocket4Net.WebSocket object on client side seems to perform the automatic reconnect (its state goes from Disconnected to Connecting to Open), but even after it reaches the Open state, the Send method is failed with exception “The socket is not connected!”

How can I eliminate this problem?
(I cannot rely on the state of the websocket object because it is already in the Open state)
Sep 21, 2014 at 8:37 PM
Could you show me your send code? Do you send after you get the [Open] event fired?
Sep 22, 2014 at 9:02 AM
Edited Sep 22, 2014 at 9:53 AM
Hi, thank you for reply.
It seems to be my fault as I wrote the message after the long nervous day. Sorry for the bothering.
The socket indeed enters the Closed state and does not reconnect automatically, it is our code that tries to open socket again, but does not wait for the completing of the process (that the state becomes Open).
Excuse me again.

The code is below:
private WebSocket _websocketClient;
public void Setup(string url, string protocol)
 _websocketClient = new WebSocket(url, protocol, WebSocketVersion.Rfc6455);
 _websocketClient.Opened += websocketClient_Opened;
 _websocketClient.MessageReceived += websocketClient_MessageReceived;
 _websocketClient.Error += websocketClient_Error;
public void Open()
protected void VerifyOpen()
 if (_websocketClient.State != WebSocketState.Open)
public void Send(string message)
Exception happens when calling _websocketClient.Send(message)and when _websocketClient.State=Open
Exception details:
System.Exception was unhandled
Message=The socket is not connected!
   at SuperSocket.ClientEngine.TcpClientSession.DetectConnected()
   at SuperSocket.ClientEngine.TcpClientSession.TrySend(ArraySegment`1 segment)
   at SuperSocket.ClientEngine.ClientSession.Send(ArraySegment`1 segment)
   at SuperSocket.ClientEngine.ClientSession.Send(Byte[] data, Int32 offset, Int32 length)
   at WebSocket4Net.Protocol.DraftHybi10Processor.SendDataFragment(WebSocket websocket, Int32 opCode, Byte[] playloadData, Int32 offset, Int32 length)
   at WebSocket4Net.Protocol.DraftHybi10Processor.SendMessage(WebSocket websocket, Int32 opCode, String message)
   at WebSocket4Net.Protocol.DraftHybi10Processor.SendMessage(WebSocket websocket, String message)
   at WebSocket4Net.WebSocket.Send(String message)
   at WebSocketConsoleClient.Client.Send(String message) in c:\Development\CodedFT\app\client\HP.CFT.Communication.Client\WebSocketConsoleClient\Client.cs:line 55
   at WebSocketConsoleClient.Program.Main(String[] args) in c:\Development\CodedFT\app\client\HP.CFT.Communication.Client\WebSocketConsoleClient\Program.cs:line 55
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.Sockets.SocketException
   Message=A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
   InnerException: (null)

Dec 22, 2014 at 7:35 AM
Try update to the latest version.