Re: Question about UdpClient?
From: Philip Rieck (junk_at_mckraken.com)
Date: 10/06/04
- Next message: Herfried K. Wagner [MVP]: "Re: How can I find out memory free and used using vb.net?"
- Previous message: One Handed Man \( OHM - Terry Burns \): "Re: Transpose data"
- In reply to: Emilio: "Question about UdpClient?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 6 Oct 2004 07:02:34 -0500
Your RemoteIpEndPoint (with IPAddress.Any, port 0) is used only as a byref
parameter - that is, it is filled in with the actual IPAddress and port that
the data came from. So you're not listening on port 0. That's just a value
you're passing to a constructor because UdpClient.Receive takes a
constructed IPEndPoint - it's not actually used. If you want to limit the
host that you can accept UDP traffic from, specify that in the Connect
method (which you seem to havedone)
"Emilio" <[void]> wrote in message
news:ufEW764qEHA.3760@TK2MSFTNGP09.phx.gbl...
> Question about UdpClient sample
>
> ' This constructor arbitrarily assigns the local port number.
> Dim udpClient As New UdpClient()
> Try
> udpClient.Connect("www.contoso.com", 11000)
>
> ' Sends a message to the host to which you have connected.
> Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
>
> udpClient.Send(sendBytes, sendBytes.Length)
>
> ' Sends message to a different host using optional hostname and port
> parameters.
> Dim udpClientB As New UdpClient()
> udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName",
> 11000)
>
> 'Blocks until a message returns on this socket from a remote host.
> Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
>
> ' Blocks until a message returns on this socket from a remote host.
> Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
> Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
>
>
> I was wondering what is the reason that when we need to receive
> a message from a remote host we do IPAddress.Any,0
> i.e why do we wait at port 0 rather than 11000, which is where
> we sent to?
>
- Next message: Herfried K. Wagner [MVP]: "Re: How can I find out memory free and used using vb.net?"
- Previous message: One Handed Man \( OHM - Terry Burns \): "Re: Transpose data"
- In reply to: Emilio: "Question about UdpClient?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|