From Overbyte
Jump to navigation Jump to search

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


method Listen;


Listen is either used on UDP sockets or on TCP-Server sockets. For UDP-sockets it makes receiving data possible, otherwise no OnDataAvailable 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.


 MySocket.addr:=''; // localhost -> myself
 MySocket.Listen; // incomming packets on port 60000 will trigger OnDataAvailable

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 as addr, you can listen on the specified port on all available network connections at the same time with the same socket.