I hate server/client code....
-
Seriously, I have been fooling around with this code for a week or so and I always end up back to sqaure 1. Can anyone see any flaws in the theoretical setup below? * I am using sockets (CLIENT/SERVER) * I use Async code for the BeginAccept and EndAccept on the socket (SERVER) * I use Async reading for the messages coming in (CLIENT/SERVER) * Using a single thread to send messages on the socket which utilizes an ArrayList of messages, clones the arraylist, does a foreach then writes each message then removes the message from the original arraylist[not the cloned] (CLIENT/SERVER) A big problem I am having is that messages will come in like: MESSAGE:blah:connect MESSAGE:blah:messageMESSAGE:blah:somethingMESSAGE:blah:networks blow And obviously I am expecting the messages to come in one at a time. I assumed that if I wrote them synchronously then the async receiving should work the way I intend. Is there a problem with this? Any help or guidance would certainly be appreciated.
-
Seriously, I have been fooling around with this code for a week or so and I always end up back to sqaure 1. Can anyone see any flaws in the theoretical setup below? * I am using sockets (CLIENT/SERVER) * I use Async code for the BeginAccept and EndAccept on the socket (SERVER) * I use Async reading for the messages coming in (CLIENT/SERVER) * Using a single thread to send messages on the socket which utilizes an ArrayList of messages, clones the arraylist, does a foreach then writes each message then removes the message from the original arraylist[not the cloned] (CLIENT/SERVER) A big problem I am having is that messages will come in like: MESSAGE:blah:connect MESSAGE:blah:messageMESSAGE:blah:somethingMESSAGE:blah:networks blow And obviously I am expecting the messages to come in one at a time. I assumed that if I wrote them synchronously then the async receiving should work the way I intend. Is there a problem with this? Any help or guidance would certainly be appreciated.
I believe that you are running into a feature of the system. When your software takes longer to read the communications from the socket, the messages will pile up. At the next read, you can then retrieve (with one call) all the messages which have been sent. So, your network protocol needs some method of delineating between the end of one message and the beginning of another. Once you have that arranged, you ought to be free of this problem. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.