Quick question, do I need to make a new class for UdpState or is there a way to incorporate the object into the form class?
Printable View
Quick question, do I need to make a new class for UdpState or is there a way to incorporate the object into the form class?
The exception text is less important than the exception type here. I'd expect an InvalidOperationException as described in http://msdn.microsoft.com/en-us/libr...vs.100%29.aspx.
As I understand your scenario, I'd first set up a UdpClient without specifying a remote host (IPEndPoint or host name). Then wait for a packet matching my protocol. When I get one I'd either settle the remote host for the UDP client I already have to the endpoint that just sent the packet in case I plan to serve just one remote host, or create another UDP client with the endpoint settled upon construction and keep the original UDP client as a promiscuous receiver for further remote host discovery. In the latter scenario, you'd have one dedicated UDP client for each discovered remote host which may seem quite some effort, but eventually it will probaly be simpler than routing all communication over the promiscuous client and dispatch it yourself. However, of course, the choice is up to you. :)Quote:
The code is now using the output parameter of EndReceive() to gather the IP address of the client. From there the receiving socket is closed and a sending socket with the acquired IP address is open to send a reply. I would imagine there is a way to send data back without opening another socket. [...]
The udpClient in your ReceiveCallback() clearly is a local variale, but what about the one in the code before that? I can't tell that which illustrates the importance of at least posting complete functions as code snippets in most scenarios. Creating UDP clients as local variables probably seems at least counter-productive performance-wise, since they get created and destroyed over and over, but it may also break your code in case the packets you expect to receive with one client have already been consumed by another one with a longer lifetime that already existed.
Unfortunately I don't have such an address. Do you happen to have a link to a free Android virtual beer app until I get one? :DQuote:
Well, I would like to offer beer money for your time in replying to my newbie questions, just PM a PayPal address if you wish. [...]