Receives a message from an open UDP Socket.
...socket_object.ReceiveFrom( input_buffer, max_length, remote_endpoint )
Prerequisites
The Socket Object must be open for UDP I/O.
The Socket Object must have been created by the udpclient_object.Client method.
Parameters
input_buffer
A ByRef String variable where the received data is stored.
max_length
The maximum number of data bytes that are read. If more bytes are available than this maximum, they are lost.
remote_endpoint
A ByRef IPEndPoint Object that receives endpoint information identifying the remote source of the received data. The original contents of remote_endpoint are ignored and replaced by the new information.
Remarks
If blocking is enabled, this method blocks until some data is received. The entire datagram is transferred by this method, if the max_length value is large enough.
Because of internal limitations on datagram size, max_length values greater than 1536 are not useful.
This method returns the number of bytes of data received. If that number is zero, this indicates that the Socket has been disconnect and should therefore be closed.
If any other network errors occur, this method throws an Exception.
Examples
Dim local_ep As New IPEndPoint("", 1234) ' Receive data for port 1234.
Dim uc As New UdpClient(local_ep)
Dim remote_ep As IPEndPoint
Dim sock As Socket
Dim input As String
Dim count As Integer
sock = uc.Client
count = sock.ReceiveFrom(input, 2000, remote_ep)
Console.Writeline("Remote IP address: " & remote_ep.IPAddress)
Console.Writeline("Remote Port: " & CStr(remote_ep.Port))
See Also