Help making this work with commands in please!?

Sep 21, 2011 at 9:20 PM

Hi, I am looking to create commands etc in a version of this code. 

In brief I have this in the global.asax

 Sub StartSuperWebSocketByConfig()

                Dim serverConfig = ConfigurationManager.GetSection("socketServer")
                If (Not SocketServerManager.Initialize(serverConfig)) Then
                End If

                Dim thisServer As WebSocketServer = SocketServerManager.GetServerByName("SuperWebSocket")
                Dim secureSocketServer As WebSocketServer = SocketServerManager.GetServerByName("SecureSuperWebSocket")

                AddHandler thisServer.NewMessageReceived, AddressOf newMessage
                AddHandler thisServer.NewSessionConnected, AddressOf socketServer_NewSessionConnected


                If (Not SocketServerManager.Start()) Then

                End If

            Catch ex As Exception
                REM Grace
            End Try

        End Sub

        Sub socketServer_NewSessionConnected(session As WebSocketSession)

            SyncLock (m_SessionSyncRoot)
            End SyncLock

        End Sub

I have created a class called ECHO with the following code

Public Class ECHO(Of websocketsession)
    Inherits SuperWebSocket.SubProtocol.SubCommandBase

    Public Overloads Overrides Sub ExecuteCommand(session As SuperWebSocket.WebSocketSession, commandInfo As SuperSocket.SocketBase.Command.StringCommandInfo)
        For Each p In commandInfo.Parameters
    End Sub
End Class

I have tried a few iterations of the class to try and get the command to fire

I am sending "ECHO Chris" to the socket server

I am using the standard socket server and standard session server, I have not created my own

Any help would be greatly appreciated!

Sep 22, 2011 at 2:07 AM

How did you send the message? The message should be send in browser by Javascript.

You can check log files for more information, all log files are in ~/Logs.

Sep 22, 2011 at 8:32 AM

I have set the log folder up but I do not appear to be getting any logs? My web.config is below

My Sockets node


<socketServer loggingMode="IndependantFile">
      <server name="SuperWebSocket"
              ip="Any" port="2011" mode="Sync" />
      <service name="OrderSocketServer" type="SuperWebSocket.WebSocketServer, SuperWebSocket" />


My Log node

<loggingConfiguration configSource="config\log4net.config" />

My config is in a sep file which I can post if you need

Here is how I call the actual code itself

<script type="text/javascript">
        var noSupportMessage = "Your browser cannot support WebSocket!";
        var wss;

        function resizeFrame() {
            var h = $(window).height();
            var w = $(window).width();
            //Adapt screen height
            $('#messageBoard').css("height", (h - 80 - 50 - 100) + "px");
            $('#messageBoxCell').css("width", (w - 100) + "px");
            $('#messageBox').css("width", (w - 110) + "px");

        $(document).keypress(function (e) {
            if (e.ctrlKey && e.which == 13 || e.which == 10) {
            } else if (e.shiftKey && e.which == 13 || e.which == 10) {

        function scrollToBottom(target) {
            target.animate({ scrollTop: target[0].scrollHeight });

        function connectSocketServer() {
            var messageBoard = $('#test');

            if (!("WebSocket" in window)) {
                messageBoard.append("* " + noSupportMessage + "<br/>");

            messageBoard.append("* Connecting to server ..<br/>");
            //setup secure websocket
            wss = new WebSocket('ws://@Request.Url.Host:2011/sample');

            // when data is comming from the server, this metod is called
            wss.onmessage = function (evt) {
                messageBoard.append("# " + + "<br />");

            // when the connection is established, this method is called
            wss.onopen = function () {
                messageBoard.append('* Secure Connection open<br/>');

            // when the connection is closed, this method is called
            wss.onclose = function () {
                messageBoard.append('* Secure Connection closed<br/>');

        function sendMessage() {
            if (wss) {
                wss.send('ECHO Chris');
            } else {

        window.onload = function () {

The code gets inserted to a p tag. I don't use the secure connection as I was just testing and getting a feel for how it worked. I have taken the sample from the examples in the download

Again, any help would be greatly appreciated and if you need anything else then please let me know.

Sep 22, 2011 at 8:36 AM

Sorry, I must add that the connection does open fine and it says connection but as soon as I press to send the message it closes the connection. On the previous release it said "unknown command".

If I put a generic handler in the asax file that handles all messages and just outputs them again then it all works fine, it's when I start trying to call classes that I get issues. I presume this is how the commands work

Sep 22, 2011 at 8:39 AM

This node

<loggingConfiguration configSource="config\log4net.config" />
is not required!

Please add the line below before you initialize SuperWebSocket:

At the same time, please ensure the config file of log4net is in your running directory /config/log4net.config.

And then run your code, if it doesn't work, then check logs for reason.
Sep 22, 2011 at 8:43 AM

Fantastic, it's reporting the logs

I get this reason

2011-09-22 08:39:33,246 [12] ERROR SuperWebSocket - No SubProtocol selected! This session cannot process any message!

Sep 22, 2011 at 8:45 AM

If you are using subprotocol(commands), please declare sub protocol in javascript. If you don't set any subprotocol name in server side's code, the default sub protocol name "basic" will be set.

So you should pass "basic" to server side as sub protocol name:

wss = new WebSocket('ws://@Request.Url.Host:2011/sample', 'basic');
Sep 22, 2011 at 8:47 AM

Sorry, I'll improve this feature, this issue blocks lots of people!

Sep 22, 2011 at 8:50 AM

OK, so I should pass the name of the command that I am calling from js? So I should pass "ECHO" where it says basic?

What happens when you have many commands from one page?

I thought the message was a key/value pair where the first part of the message routed it to a class then passed a message to the ExecuteCommand?

It's been especially hard for me to follow the code if I am honest with it being c#, I really need to get out of!

Thanks for the help

Sep 22, 2011 at 8:53 AM


wss = new WebSocket('ws://@Request.Url.Host:2011/sample', 'basic');
Sep 22, 2011 at 8:57 AM

many commands is very easy, define more commands in server side, and then send message with these commands' name as prefix


ws.Send("ECHO hello");  - ECHO command

ws.Send("LOGIN username password"); - LOGIN command

ws.Send("QUIT");   - QUIT command

Sep 22, 2011 at 9:00 AM

Well, I am no longer getting any errors! Although nothing is being sent to the browser. I am getting nothing at all, not even errors in Chrome, no activity

Is my command class setup properly?

Public Class ECHO
    Inherits SuperWebSocket.SubProtocol.SubCommandBase(Of WebSocketSession)

    Public Overloads Overrides Sub ExecuteCommand(session As SuperWebSocket.WebSocketSession, commandInfo As SuperSocket.SocketBase.Command.StringCommandInfo)

        session.SendResponse("From command")

    End Sub
End Class

I presume this is how it works, it uses reflection to find the ECHO command of type SubCommandBase?

I'm really sorry to be pestering but I really do appreciate it

Sep 22, 2011 at 10:10 AM
Public Class ECHO
    Inherits SuperWebSocket.SubProtocol.SubCommandBase

is ok enougth, Of WebSocketSession is not requred, but they should be same.

You should debug into the code to check problems.

Sep 22, 2011 at 8:12 PM

Hi, thanks for the help so far

I still can't seem to be getting a response from the server

I only have 3 files, the asax, the page with the js on and the command which I want to execute and I still cannot seem to get anywhere?

Should I have any type of handler setup in the asax or does the command auto wireup?

The server is connecting but nothing happens at all when I send the message, like nothing is due to return?

I due not have much I can debug, if I put breakpoints in the command, nothing is being called, the rest of the code is the SuperWebSocket dll?

The logs do not appear to be reporting any errors either?


Sep 23, 2011 at 2:10 AM

Oh, I may get the reason,

you should create new library project to put your commands and then set commandAssemply in server's config.

Please take a look at this guide:


You should follow  the CommandAssembly project in samples folder!