Difference between revisions of "TWSocket.Port"
Markus.humm (talk | contribs) (added examples) |
Markus.humm (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 9: | Line 9: | ||
=== Client === | === Client === | ||
− | This specifies the port on the server where a connect will connect you. This only applies to [[TCP]], since [[UDP]] doesn't use the client/server sheme. | + | 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 === | === Server === | ||
Line 21: | Line 21: | ||
=== TCP client === | === TCP client === | ||
+ | <syntaxhighlight lang="delphi"> | ||
WSocket1.addr:='192.168.0.1'; // Address to connect to | WSocket1.addr:='192.168.0.1'; // Address to connect to | ||
WSocket1.port:='5000'; // Port to connect to | WSocket1.port:='5000'; // Port to connect to | ||
WSocket1.proto:='tcp'; | WSocket1.proto:='tcp'; | ||
WSocket1.connect; // actually do the connect | WSocket1.connect; // actually do the connect | ||
+ | </syntaxhighlight> | ||
=== TCP server === | === TCP server === | ||
+ | <syntaxhighlight lang="delphi"> | ||
WSocket1.addr:='192.168.0.1'; // Address to connect to | WSocket1.addr:='192.168.0.1'; // Address to connect to | ||
WSocket1.port:='5000'; // Port to connect to | WSocket1.port:='5000'; // Port to connect to | ||
Line 33: | Line 36: | ||
WSocket1.listen; // wait for incomming connections | WSocket1.listen; // wait for incomming connections | ||
// but return immediatelly | // but return immediatelly | ||
+ | </syntaxhighlight> | ||
=== UDP === | === UDP === | ||
+ | <syntaxhighlight lang="delphi"> | ||
WSocket1.addr:='192.168.0.1'; // Address to connect to | WSocket1.addr:='192.168.0.1'; // Address to connect to | ||
WSocket1.port:='5000'; // Port to connect to | WSocket1.port:='5000'; // Port to connect to | ||
Line 41: | Line 46: | ||
WSocket1.listen; // incomming data will directly raise | WSocket1.listen; // incomming data will directly raise | ||
// OnDataAVailable | // OnDataAVailable | ||
+ | </syntaxhighlight> | ||
== Best practices == | == Best practices == | ||
== How to == | == How to == |
Latest revision as of 20:35, 1 July 2010
Main page -> ICS component reference -> TWSocket -> Port
Contents
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>