System.Net.Socket.TSocket.InitSocket
Delphi
function InitSocket(const Name, Address, Service: string; Port: Word; Client: Boolean; Broadcast: Boolean = False): sockaddr_in;
C++
sockaddr_in __fastcall InitSocket(const System::UnicodeString Name, const System::UnicodeString Address, const System::UnicodeString Service, System::Word Port, bool Client, bool Broadcast = false);
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | protected | System.Net.Socket.pas System.Net.Socket.hpp |
System.Net.Socket | TSocket |
Description
Returns a sockaddr_in structure configured based on the specified parameters.
InitSocket determines the socket address differently depending on the specified arguments:
- If
Name
is not an empty string, InitSocket performs a DNS lookup of the specified string. - If
Address
is not an empty string, InitSocket uses that address.Address
must be an IPv4 address. For example: "192.0.2.4". - If your socket is a broadcast socket (
Broadcast
isTrue
) or a server socket (Client
isFalse
), you do not need to specify an address.
InitSocket determines the socket port differently depending on the specified arguments as well:
- If
Service
is not an empty string, InitSocket looks up the port matching the specified service name. - Otherwise, InitSocket uses the value that you specify for the
Port
parameter.
Exceptions
A call to InitSocket can raise any of the following exceptions:
Exception | Exception.Message | Scenarios |
---|---|---|
No address specified |
|