Get 'SocketAddress' when receiving a packet

Monkey Forums/Monkey Programming/Get 'SocketAddress' when receiving a packet

ImmutableOctet(SKNG)(Posted 2013) [#1]
I've been working on a high-level UDP networking library/module, and it currently supports QuickSock and ANet. Since we now have 'BRL.Socket', I thought I'd add an option to support it. Everything seems to be in order, but I'm still not sure how I'm supposed to get the 'SocketAddress' (IP address and port) of whoever sends me a packet.

I can only assume the 'RemoteAddress' property is what I want, but I'm not 100% sure about this. Is this functionality even supported currently? Do I have to use a workaround? Did I get it right with the 'RemoteAddress' property?

I'll probably just look into the native code if I don't get a straight answer.

EDIT: After looking into it; is Accept what I'm looking for? Or is that TCP only?


marksibly(Posted 2013) [#2]
Use ReceiveFrom on a UDP socket to get the address of sender. In general, with UDP sockets:

* Use Send/Receive if the UDP socket is connected, otherwise use SendTo/ReceiveFrom. If a UDP socket is connected, it's peer's address is known so Send/Receive don't need any extra address information.

Have a look at the bananas/mak/echoserver_udp sample.


ImmutableOctet(SKNG)(Posted 2013) [#3]
Thanks Mark, that should work. I know there's no need for it for clients, I was mainly talking about the server's socket. I didn't realize ReceiveFrom gave you the address, that makes a lot more sense.