David,
Good idea...
The code below is a sample from the VS help... very straight forward. No
default host is set with the connect method so it should receive from any
host... it doesn't
It bangs out saying:
---------
System.Net.Sockets.SocketException: Invalid Argument
at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 size,
SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sockets.UdpClient.Receive(IPEndPoint& remoteEP)
---------
********
Private Function MicrosoftSample() As Integer
'Creates a UdpClient for reading incoming data.
Dim receivingUdpClient As New UdpClient
'Creates an IPEndPoint to record the IP address and port number of
the sender.
' The IPEndPoint will allow you to read datagrams sent from any
source.
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Try
' Blocks until a message returns on this socket from a remote
host.
Dim receiveBytes As [Byte]() =
receivingUdpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
Console.WriteLine(("This is the message you received " +
returnData.ToString()))
Console.WriteLine(("This message was sent from " +
RemoteIpEndPoint.Address.ToString() + " on their port number " +
RemoteIpEndPoint.Port.ToString()))
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Function
*******
If I create an instance of an IPEndpoint and set it to the remotehost, this
occurs just the same. If I first use the connect method to set the default
host, the code hangs in the receive method as if there is nothing to receive.
(I KNOW that is not true)
Peter