Server side, initiating a message on existing socket?

Feb 12, 2012 at 5:44 PM

Much of what I see in the AppServer, Protocol, Command, etc is about when the client formulates a message and sends it to the server and a response is sent. I have this all working great.  But at times I need to initiate the message going from the server to the client.  I've tried to get a hold of the session and simply jamming a string into the SendResponse, but then it doesn't show up in my StreamReader. 

When I do this, at this point, I do get NetworkStream.DataAvailable = true, but when I do a StreamReader.Peek i get -1.  And of course, StreamReader.ReadLine just stalls.  And yes, I am putting a Environment.NewLine into the response.

Thanks for your help.


Feb 13, 2012 at 12:49 AM

I think your problem is protocol analysis in your client side. If you don't want command line format response (you can get them by ReadLine()), you need do more works. Could you look at the code of WebSocket4Net?

Feb 13, 2012 at 4:00 AM

Let me give a little more information.  My socket server is inside a desktop WPF app.  The client is something that is hosting a flash swf file.  From inside flash, it can only be a client.  I need to be able to initiate json-rpc messages in both directions (.net server->flash and flash->.net server).  I don't want polling on either side.

One of my problems at the moment is that I am trying to write a unit test, that starts the server and simulates the client.  when I simulate initiating the client I get the stall. So i know my client isn't correct.  With that said, you mention "need to do more works", what are you referring to?

When you say look at the code for WebSocket4Net can you point me to something?  On my initial look, I didn't see anything that fits a server initiating a message.  I do like the look of this though, wished I had seen it before, I built up around supersocket.

By the way, your work is much appreciated.  I've come a long ways in just a couple days and I didn't know much of anything about sockets.  I'm just gonna need a little help to get me there :)




Feb 13, 2012 at 4:06 AM

Oh, what's you want is how to send message to client initially from server side?

If so, you should read the documentation:

Feb 14, 2012 at 2:15 AM

Great. I will give this all a better look.