SendResponse from server works only after a first message from the client

Dec 11, 2012 at 8:16 AM
Edited Dec 11, 2012 at 8:17 AM

I am not sure whether this is normal behaviour.

 

I create an instance of the WebsocketServer

 

 

 m_wsServer = new WebSocketServer();
                m_wsServer.Setup(new RootConfig(), new ServerConfig
                {
                    Port = SettingsReader.SrvSettings.WebSocketConfiguration.NonSecurePort,
                    Ip = "Any",
                    MaxConnectionNumber = 100,
                    Mode = SocketMode.Sync,
                    Name = "WebsocketServer"
                }, SocketServerFactory.Instance);
                m_wsServer.NewMessageReceived += new SessionEventHandler<WebSocketSession, string>(OnMessageReceived);
                m_wsServer.NewSessionConnected += new SessionEventHandler<WebSocketSession>(OnConnectedClient);
                m_wsServer.SessionClosed += new SessionEventHandler<WebSocketSession, CloseReason>(OnDisconnectedClient);

 

 

Everything works fine only if the first message after the handshake is sent from the client.

On the other hand, if I try to do this

 

 

        public void OnConnectedClient(WebSocketSession websocketSession)        {

websocketSession.SendResponse("Some nice compliments");

}

In such a case, the message is not sent. Any suggestions?

Coordinator
Dec 11, 2012 at 8:19 AM

Does the sample SuperWebSocketWeb work for you? You also can check the Test project which should can run correctly by NUnit.

Dec 11, 2012 at 8:27 AM

The whole library works rather nicely actually, I haven't tested your samples because my websocket server works just fine.

The only thing I don't understand is why I cannot send messages from the server until I receive a first message from the client.

Coordinator
Dec 11, 2012 at 8:38 AM

I think you can send data from the server after the handshake of the session is done.

There is a virtual method "OnHandshaked()" in WebSocketSession, which you can use.

Dec 11, 2012 at 8:53 AM

That's not the problem.

The handshake is finished and the websocket is open on both sides.

If I try to send a message from server to client, I cannot do it until the client sends a message first.

Coordinator
Dec 11, 2012 at 9:01 AM

Can you test this issue by the sample project SuperWebSocketWeb?

Send message from one browser and the get the message from the other browser.

Dec 11, 2012 at 9:11 AM

I'm afraid I won't be able to invest time on this.

For the moment I'll just send a message from the client-side to actually 'open' the communication, hopefully it'll be enough.