Send JSON command to client

Feb 23, 2012 at 7:28 AM
Edited Feb 23, 2012 at 7:28 AM


If find SuperWebSockets to be a very good library but I have one question that I can't find the answer for.

What is the best way for the server to send a command to the client? I mean if it is the server that should initiate the command and not the client. Can I somehow send a JsonSubCommand to the client and if so how is the response handled?

Now I send the client a command using the following method but it seems like there should be a better solution.

private void SendCommand(WebSocketSession session, string name, object parameters)
  session.SendResponse(name + " " + JsonConvert.SerializeObject(parameters));


Feb 23, 2012 at 8:26 AM

It looks ok. The key point should be find the session which you want by the server, and then send.

Feb 23, 2012 at 1:45 PM

Thanks for the reply!

Finding the session will not be a problem since we will use WebSockets to communicate between a web application and a windows application running on localhost. So there should really be only one session! 

Feb 23, 2012 at 1:49 PM

The documentation of SuperSocket may be helpful for you:

Feb 23, 2012 at 1:50 PM

Yes, I have already found that. Thanks!