ExecuteJsonCommand doesn't fire

Nov 13, 2013 at 5:25 PM
Edited Nov 13, 2013 at 6:15 PM
Hello everyone! Could you please help me? I'm trying to implement Wsocket server with some Json commands and call those commands from Chrome's built in WSockets but my commands don't fire :( What should I change? I have implemented one simple command Login.
namespace SWTest
{
    using SuperWebSocket;
    using SuperWebSocket.SubProtocol;


    public class CallWayServer : WebSocketServer<CallWaySession>
    {
    }
        public class CallWaySession : WebSocketSession<CallWaySession>
    {
    }

    public class Login: JsonSubCommand<CallWaySession, UserCredentials>
    {
        protected override void ExecuteJsonCommand(CallWaySession session, UserCredentials commandInfo) {
// doesn't fire :(
        }

        public override void ExecuteCommand(CallWaySession session, SubRequestInfo requestInfo) {
// this one fires :(
        }
    }

    public class UserCredentials
    {
        public string Login {get;set;}
        public string Password {get;set;    }
    }
}
This is how I start server.
private CallWayServer _callWayServer;
...
            _callWayServer = new CallWayServer();
            _callWayServer.Setup(4205);
            _callWayServer.Start();
This is how I call it from Chrome.
            $('#btnSend').on('click', function () {
                conn.send('Login ' + JSON.stringify({ Login: 't1', Password: '' }));
            });
Coordinator
Nov 14, 2013 at 2:07 AM
Did you check the log files for more details? Put the log4net.config into the "Config" directory.
Nov 14, 2013 at 6:09 PM
Edited Nov 14, 2013 at 6:10 PM
kerryjiang wrote:
Did you check the log files for more details? Put the log4net.config into the "Config" directory.
Ок. I have got logs.

debug.log

2013-11-14 19:55:01,144 [8936] DEBUG CallWayServer-37368736 - SubProtocol Basic found the commands below:
Login

2013-11-14 19:55:01,166 [8936] DEBUG CallWayServer-37368736 - Listener (0.0.0.0:4205) was started

Well, I have tried to debug and found some logic which checks if Body is not empty then EcecuteCommand otherwise - ExecuteJsonCommand but don't know how to force Body to be empty.
public abstract class JsonSubCommandBase<TWebSocketSession, TJsonCommandInfo>: SubCommandBase<TWebSocketSession>{
....
 public override void ExecuteCommand(TWebSocketSession session, SubRequestInfo requestInfo)
    {
      if (string.IsNullOrEmpty(requestInfo.Body))
      {
        this.ExecuteJsonCommand(session, default (TJsonCommandInfo));
      }
      else
      {
        if (!string.IsNullOrEmpty(requestInfo.Token))
          session.CurrentToken = requestInfo.Token;
        TJsonCommandInfo commandInfo = this.m_IsSimpleType ? (TJsonCommandInfo) Convert.ChangeType((object) requestInfo.Body, this.m_CommandInfoType) : (TJsonCommandInfo) session.AppServer.JsonDeserialize(requestInfo.Body, this.m_CommandInfoType);
        this.ExecuteJsonCommand(session, commandInfo);
      }
    }
....

}
Coordinator
Nov 15, 2013 at 2:33 AM
Did you run the sample projects? You should try plain text first instead of json object.
Nov 15, 2013 at 6:46 AM
kerryjiang wrote:
Did you run the sample projects? You should try plain text first instead of json object.
Yes, I did, but it didn't help much :(
Could you please point me out what I do wrong?

Thank you anyway.
Coordinator
Nov 15, 2013 at 6:51 AM
You did?

Does it work for you? Did you try send plain text parameter first?
Nov 15, 2013 at 7:22 AM
Edited Nov 15, 2013 at 7:31 AM
kerryjiang wrote:
You did?

Does it work for you? Did you try send plain text parameter first?
Well, I hope screenshots will help you to trust me :) Project A-BasicConsole
Image
and
Image

And next B-SubProtocol also works.
Image
Coordinator
Nov 15, 2013 at 8:11 AM
I mean if it works for you, you'd better align your code to the sample code, then everything should work.

I also have no idea about your problem if your code does the same way.
Coordinator
Nov 15, 2013 at 8:11 AM
BTW, the Test project also can help you identify the problem.
Nov 15, 2013 at 8:17 AM
kerryjiang wrote:
BTW, the Test project also can help you identify the problem.
Ок, I'll check Test project. Could you please write a basic example which configures server programmatically and executes one Json command so I could debug it?
Thank you.
Coordinator
Nov 15, 2013 at 8:19 AM
It is what the Test project does, which locates in the source code.
Nov 15, 2013 at 8:24 AM
kerryjiang wrote:
It is what the Test project does, which locates in the source code.
:) Well, there is no test wich covers JsonCommand :(
Coordinator
Nov 15, 2013 at 8:33 AM
Ok, just debug your code, set the break point to the WebSocketServer.cs, method "void ExecuteMessage(TWebSocketSession session, string message)", to check the value of the message.

Do you have any IM? Like Skype, my Skype: kerry-jiang
Marked as answer by ISkomorokh on 11/17/2013 at 11:27 PM
Nov 15, 2013 at 8:42 AM
Have sent you my skype by email.
Nov 18, 2013 at 7:39 AM
kerryjiang wrote:
Ok, just debug your code, set the break point to the WebSocketServer.cs, method "void ExecuteMessage(TWebSocketSession session, string message)", to check the value of the message.

Do you have any IM? Like Skype, my Skype: kerry-jiang
Thank you kerryjiang for your help.

4 the rest there were 2 problems:
  1. Incompatible Newtonsoft.Json version which caused silent exception during assembly loading.
  2. Presens of ExecuteCommand override in Login command which is derived from JsonSubCommand<> ans suppose to have only ExecuteJsonCommand override. When both are present - ExecuteCommand wins.
Enabling of logging also helped.