This project is read-only.

How to use demo code

Mar 8, 2012 at 2:08 PM

- I was created websocket server with the port number 2012, using superwebsocket server.

- Using the websocket client demo code i was trying to send message.

- Throwing error, client called server closed event reason "ClientClosing"

- Client Code:

WebSocket websocket = new WebSocket("ws://");

        static void Main(string[] args)
            Program p = new Program();
        private void Start()
            websocket.Opened += new EventHandler(websocket_Opened);
            websocket.Error+=new EventHandler<ErrorEventArgs>(websocket_Error);
            websocket.Closed += new EventHandler(websocket_Closed);
            websocket.MessageReceived+=new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);

        private void websocket_Opened(object sender, EventArgs e)
            websocket.Send("Hello World!");

        private void websocket_Error(object sender, ErrorEventArgs e)
        private void websocket_Closed(object sender, EventArgs e)
        private void websocket_MessageReceived(object sender, MessageReceivedEventArgs e)


Mar 8, 2012 at 2:14 PM

Did you get any error in the method below?

private void websocket_Error(object sender, ErrorEventArgs e)

Mar 8, 2012 at 2:25 PM

NO, I did not get any error

Mar 8, 2012 at 2:27 PM

I mean did you print the client error?

Mar 8, 2012 at 2:38 PM

Thanks for the replay kerry..

None of the events called in the client code.  But in the server log new session has been created and closed immediatly.

Server logs:

2012-03-08 19:54:31,840 [15216] INFO  Session: 2583a05c-0a49-4b7b-a7ac-efe9ef2db272/
New SocketSession was accepted!
2012-03-08 19:55:54,894 [16088] INFO  BroadCasting - Session: 2583a05c-0a49-4b7b-a7ac-efe9ef2db272/
This session was closed!



Mar 8, 2012 at 2:39 PM

whether the client_Open was fired?

Mar 8, 2012 at 2:40 PM

Is there any log in err.log of server side?

Mar 8, 2012 at 2:42 PM
Edited Mar 8, 2012 at 2:43 PM

nothing logged in the server err.log

I thought the problem in handshake..

I put break point at "Sendhandshake" override method (class name "DraftHybi10Processor.cs") in the client code.

By the time cursor reach to the handshake builder in the code, cursor was jumped to server close event, reason is clientclosing


Mar 9, 2012 at 1:30 AM

I had some problems with events not getting called when I upgraded.  I don't know if this is all required, but I recommend this pattern when websocket4net is updated:

1) Build the libraries (build.bat)

2) Delete bin and obj folders from your project folder

3) Remove reference to websocket4net

4) add reference to updated websocket4net dll in your project


Worth a try maybe :)