Feb 9, 2012 at 7:33 PM

I need to send/receive JSON messages over a web socket.   I assume that I would have to create a JsonWebSocket class instead of a WebSocket.  However, the Send method requires a name.   What is the reason that the Send method require name?  Does the name need to unique?  Do you need to call the RegisterHandler before calling Send?   I'm confused how does work?  If I send a message with name + " " + JSON message, the server does not understand the message.   I can add another Send method that does not require a name and change the receive method to handle that.    What do you think?



Feb 10, 2012 at 12:32 AM

JsonWebSocket is designed to work with JSON sub command of SuperWebSocket.

Your requirement is reasonable, I am going to improve it

Feb 10, 2012 at 2:11 AM

Thank you.  In the current version, do we need to call the RegisterHandler before we call send?

Feb 10, 2012 at 2:12 AM

No, RegisterHandler is used for processing received JSON messages.

Feb 12, 2012 at 10:01 AM

Hello smo7k, a name required is reasonable. Because there should be many types json messages will be transferred between client and server, the name is used for telling the other side of the network which type should be used for deserializing the json message.

Feb 12, 2012 at 2:40 PM

I agree that there should have name to identify the type of messages.  But there are many ways to do.  One way is yours.  Other way is to put a name key inside the json message that is what we do (It might not be the best way, but that is how my server expects).  We deserial to a base message class and have switch statement based on the name in the json to tell us what message it is.  It is no big deal.  I can write my own JsonWebSocket class base on your WebSocket.  Thank you for your response.

Feb 12, 2012 at 2:42 PM

Yes, you got the idea!

Jan 12, 2015 at 4:51 PM
Hello, smo7k. Did you write your own JsonWebSocket? I need the same solution like you described. Please, answer me. Thanks a lot.