So I'm trying to get two applications talking on the same computer using the handy MFC CAsyncSocket class, using UDP datapackets. I'm using this sample, and have emulated the same behavior in my own application: http://support.microsoft.com/kb/214396
I derived my own socket class from CAsyncSocket , and here's the behavior in pseudocode, with some sample comm info filled in:
application 1 init:
socket.Create(4000, SOCK_DGRAM); // create the local socket on port 4000
application 2 init:
socket.Create(4001, SOCK_DGRAM); // create the local socket on port 4001
application 1 send:
socket.SendTo("hello", 4001, "127.0.0.1") // say hello to other app's port
application 2 receive:
OnReceive event fires
The weird part is that if application 2 is not running when I send the message from application 1, the OnReceive event of *application 1* fires, with a "Connection reset by peer" error. So four questions:
a) is this behavior by design, or is something funny going on?
b) if this is by design, what's up with that? I thought datagrams were supposed to be connectionless, and just send a message without regard (or errors) to whether it was heard
c) would this also occur if they were on different machines, or is this some loopback effect? (I will eventually try this, but would appreciate an insight)
d) is the capital-R "Right" way to handle this (if I don't care if target is running) simply to filter out anything with that error in my sender's OnReceive event?
Thanks very much for any thoughts and help.
(this Q is the spiritual successor to http://www.experts-exchange.com/Programming/Languages/CPP/Q_25015367.html
; but no need to read it)