ASIO newbie: Passing parameters from a TCP client to a server
Hello all, I have studying the ASIO examples, and experimenting with them. Still, I could benefit from the guidance of experienced programmers. This is my first client-server set of apps. I need the client to pass a few arguments to the server, lets say four. Should I pass them in 4 different lines? Being synchronous I suppose the client blocks until the server performs a read? (that seems to be what I am seeing now). I heard that there are ways to attach the debugger (gdb) to a server process when it starts? (that feat seems to be major wizardry). Sample code would be very appreciated. TIA, -Ramon
I need the client to pass a few arguments to the server, lets say four.
Should I pass them in 4 different lines?
ASIO sends your buffer as is, and doesn't care about the format of the data. The format is a matter of agreement between your server and your client.
Being synchronous I suppose the client blocks until the server performs a read? (that seems to be what I am seeing now).
Synchronous "send" blocks until the data is sent.
On Sat, Sep 19, 2009 at 6:21 PM, Ramon F Herrera
I need the client to pass a few arguments to the server, lets say four.
Should I pass them in 4 different lines?
Generally, it is a much more futureproof idea not to that straight forward but: a) wrap your data in somthing well structured and parseable such as boost serialization or google protocol buffers or even XML b) send the resulting wrapped up data using a well defined transport layer such as HTTP, also suitable for calls That way, you won't have to worry about this sort of self made protocol that tends to become a pain in the source more quickly than you'd think.
Being synchronous I suppose the client blocks until the server performs a read? (that seems to be what I am seeing now).
pretty much. For details read Stevens. Very useful when one starts with that sort of thing.
I heard that there are ways to attach the debugger (gdb) to a server process when it starts? (that feat seems to be major wizardry).
No big deal. GDB can do that and even Microsoft's Visual Studio debugger. Read the appropriate docs. ( $> gdb /path/to/your_binary $PID )
Sample code would be very appreciated.
Look at the example programs in the boost asio docs. Or, if not so familiar with modern day C++ at the examples in Steven's Book Unix Network Programming. Both are excellent starting points, depending on _where_ you start from and where you want to end up. Cheers, Stephan
participants (3)
-
Igor R
-
Ramon F Herrera
-
Stephan Menzel