Remote IP and Port of a UDP socket

BlitzMax Forums/BlitzMax Programming/Remote IP and Port of a UDP socket

Shagwana(Posted 2008) [#1]
How can you get the remote IP and port of a udp sent message?. The supplied commands dont work at all.

SocketLocalIP()
SocketLocalPort()
SocketRemoteIP()
SocketRemotePort()


As I understand it, the UDP packet should have the source information present in its header, so this should be possible!


Winni(Posted 2008) [#2]
I think the problem is that you do not have a socket that is bound to a remote IP and port, and above functions only work with such sockets.

Usually, to get a socket that is bound to a remote host, you'd create a local listening socket and create new sockets for each incoming request via SocketAccept(). Those new sockets carry the remote information that you want to obtain, but the problem is that this approach only works with TCP connections.

UDP was designed for so-called unreliable communication, and that basically translates to that you have an application that does not even expect a reply from the other machines that it is sending to.

It does not seem as if BlitzMax had any features implemented that would allow you to open the received UDP packages and analyze the header info. When you are writing both the server and client app, just make sure that your client app is transmitting the necessary information in its messages. If this is not the case, you will probably have to write some wrapper functions for the sockets API of your OS.


Dreamora(Posted 2008) [#3]
Use BNetEx by Vertex

It gives you the possibility to retrieve the remote data of a package and is cross plattform and wraps TStream for its usage which is a quite nice feature :) (especially if you come up with the idea of extending that in a decorators so you start to stream data straight from file -> UDP / TCP)