System.Net.Socket.TSocket.Listen
Delphi
procedure Listen(const Address, Service: string; Port: Word; QueueSize: Integer = -1); overload;
procedure Listen(const Endpoint: TNetEndpoint; QueueSize: Integer = -1); overload;
C++
void __fastcall Listen(const System::UnicodeString Address, const System::UnicodeString Service, System::Word Port, int QueueSize = 0xffffffff)/* overload */;
void __fastcall Listen(const TNetEndpoint &Endpoint, int QueueSize = 0xffffffff)/* overload */;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | System.Net.Socket.pas System.Net.Socket.hpp |
System.Net.Socket | TSocket |
Description
Configures the socket to begin accepting incoming connections.
After you call Listen, you must call Accept to actually accept an incoming connection and establish a communication channel with that client.
To specify the endpoint where your socket listens, you must provide either of the following combinations of parameters:
- An endpoint (
Endpoint
). - An IP address (
Address
) and a service (Service
). You may pass an empty word asPort
, asService
is used to determine the port. - An IP address (
Address
) and a port (Port
). Pass an empty string asService
, otherwise the specified service name is used to determine the port to use, and the specified port is ignored.
QueueSize
determines the maximum length of the queue of pending connections. See listen function in the MSDN. Use -1
for the maximum recommended length of the queue (default).
Exceptions
A call to Bind can raise any of the following exceptions:
Exception | Exception.Message | Scenarios |
---|---|---|
Can't create new socket |
| |
Can't listen on an open socket |
| |
Network socket error: <error message> (<error code>), on API 'bind' |
| |
Network socket error: <error message> (<error code>), on API 'listen' |
| |
Network socket error: <error message> (<error code>), on API 'socket' |
|