TWSocket.Listen

From Overbyte
Revision as of 10:46, 21 September 2006 by Markus.humm (talk | contribs) (first entry)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Definition

method Listen;

Description

Listen is either used on UDP sockets or on TCP-Server sockets. For UDP-sockets it makes receiving data possible, otherwise no OnataAvailable would be triggered, for TCP-Servers it starts to watch for incomming new connections, which trigger OnSessionAvailable. Listen does not block the calling thread. It may throw a exception if the ip/port combination the socket should listen on is already in use with the same protocol (TCP/UDP). Some already by TCP used ip/port combination can be used simultaniously by a UDP connection as well.

Example

 MySocket:=TWSocket.create(nil);
 MySocket.addr:='127.0.0.1';
 MySocket.port:='60000';
 MySOcket.proto:='udp';
 MySocket.Listen;

Best practices

  • set up addr and port before calling listen
  • put a try/except around the listen call

How to

listen on all network interfaces simultaniously

When you specify 0.0.0.0 as addr, you can listen on the specified port on all available network connections at the same time with the same socket.