Share via


Visual Basic: Winsock Control

LocalPort Property

See Also    Example    Applies To

Returns or sets the local port to use. Read/Write and available at design time.

  • For the client, this designates the local port to send data from. Specify port 0 if the application does not need a specific port. In this case, the control will select a random port. After a connection is established, this is the local port used for the TCP connection.

  • For the server, this is the local port to listen on. If port 0 is specified, a random port is used. After invoking the Listen method, the property contains the actual port that has been selected.

Syntax

object.LocalPort = long

The object placeholder represents an object expression that evaluates to an object in the Applies To list.

Data Type

Long

Remarks

Port 0 is often used to establish connections between computers dynamically. For example, a client that wishes to be "called back" by a server can use port 0 to procure a new (random) port number, which can then be given to the remote computer for this purpose.