TWSocket.Port

From Overbyte
Jump to navigation Jump to search

Main page -> ICS component reference -> TWSocket -> Port

Definition

property Port: string;

Description

Client

This specifies the port on the server where a connect will connect you to. This only applies to TCP, since UDP doesn't use the client/server sheme. For UDP the port is nevertheless important. The UDP-socket listens on this port but for sending data to a UDP socket you don't need to connect but rather use the SendTo method instead of Send.

Server

The port on the interface where the server will listen either for incomming connections and data (TCP) or for data only (UDP). If a TCP server specified '0.0.0.0' for Addr, the port is available on all IP-adresses the server currently posseses (including 127.0.0.1 and dial in internet connections).

Under windows the netstat command may be used to check which ports are already in use and by what application. Call netstat -? for details on its usage.

Example

TCP client

<syntaxhighlight lang="delphi">

 WSocket1.addr:='192.168.0.1'; // Address to connect to
 WSocket1.port:='5000';        // Port to connect to
 WSocket1.proto:='tcp';
 WSocket1.connect;             // actually do the connect

</syntaxhighlight>

TCP server

<syntaxhighlight lang="delphi">

 WSocket1.addr:='192.168.0.1'; // Address to connect to
 WSocket1.port:='5000';        // Port to connect to
 WSocket1.proto:='tcp';
 WSocket1.listen;              // wait for incomming connections 
                               // but return immediatelly

</syntaxhighlight>

UDP

<syntaxhighlight lang="delphi">

 WSocket1.addr:='192.168.0.1'; // Address to connect to
 WSocket1.port:='5000';        // Port to connect to
 WSocket1.proto:='udp';
 WSocket1.listen;              // incomming data will directly raise 
                               // OnDataAVailable

</syntaxhighlight>

Best practices

How to