socket_object.Receive Method

Receives a message from an open TCP connection.

...socket_object.Receive( input_buffer, max_length )

Prerequisites

An active TCP connection must exist for the Socket.

The Socket Object must have been created by the tcpclient_object.Client method or the tcplistener_object.AcceptSocket 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 must be read by subsequent Receive method calls.

Remarks

If blocking is enabled, this method blocks until some data is received. There is no guarantee that an entire datagram is received at once.

This method returns the number of bytes of data received. If the number is zero, this indicates that the TCP connection has been broken by either the local or remote endpoint.  In this case, the program should close the Socket.

If any other network errors occur, this method throws an Exception.

Examples

Dim ep As New IPEndPoint("192.168.0.3", 1234)
Dim tc As New TcpClient(ep)
Dim sock As Socket
Dim input As String
Dim count As Integer
sock = tc.Client
count = sock.Receive(input, 2000)

See Also

Networking Classes | socket_object.ReceiveFrom