Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UDP Listener Question

0 views
Skip to first unread message

Jesse Zan

unread,
Jun 13, 2003, 4:13:11 PM6/13/03
to
If a remote UDP server is sending data to a port on the local computer how
do you get the IP address of that remote server?


Chris Coddington

unread,
Jun 16, 2003, 9:00:58 PM6/16/03
to
Does this not work?

IPAddress.Parse(CType(s.RemoteEndPoint, IPEndPoint).Address.ToString())

In which s = your socket?

l8tr - Chris

"Jesse Zan" <jz...@hotmail.com> wrote in message news:<#yCl3geM...@TK2MSFTNGP10.phx.gbl>...

Rich Blum

unread,
Jun 18, 2003, 9:08:10 AM6/18/03
to
"Jesse Zan" <jz...@hotmail.com> wrote in message news:<#yCl3geM...@TK2MSFTNGP10.phx.gbl>...
> If a remote UDP server is sending data to a port on the local computer how
> do you get the IP address of that remote server?

Jesse -

It depends on how the UDP socket was created on the local
computer. If you use the UdpClient class, it would look like:

Dim iep as New IPEndPoint(IPAddress.Any, 9050)
Dim sock as New UdpClient(iep)
Dim iep2 as New IPEndPoint(IPAddress.Any, 0)
Dim data as byte()
data = sock.Receive(ref iep2)
Console.WriteLine("The remote host is: {0}, port {1}", _
iep2.Address, iep2.Port);

If you use the Socket class, it would look like:

Dim iep as New IPEndPoint(IPAddress.Any, 9050)
Dim sock as New Socket(AddressFamily.InterNetwork, _
SocketType.Dgram, _
ProtocolType.Udp)
sock.Bind(iep)
Dim iep2 as New IPEndPoint(IPAddress.Any, 0)
Dim sender as EndPoint
Dim data as byte()
Dim recv as int
sender = (EndPoint)iep2
recv = sock.ReceiveFrom(data, ref sender)
Console.WriteLine("The remote host is: {0}", sender.ToString())

Hope this helps out some.

Rich Blum
Author of "C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176

0 new messages