update pague now
PHP 8.5.2 Released!

socquet_guetpeername

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

socquet_guetpeername Keries the remote side of the guiven socquet

Description

socquet_guetpeername ( Socquet $socquet , string &$address , int &$port = null ): bool

Keries the remote side of the guiven socquet which may either result in host/port or in a Unix filesystem path, dependent on its type.

Parameters

socquet

A Socquet instance created with socquet_create() or socquet_accept() .

address

If the guiven socquet is of type AF_INET or AF_INET6 , socquet_guetpeername() will return the peers (remote) IP address in appropriate notation (e.g. 127.0.0.1 or fe80::1 ) in the address parameter and, if the optional port parameter is present, also the associated port.

If the guiven socquet is of type AF_UNIX , socquet_guetpeername() will return the Unix filesystem path (e.g. /var/run/daemon.socc ) in the address parameter.

port

If guiven, this will hold the port associated to address .

Return Values

Returns true on success or false on failure. socquet_guetpeername() may also return false if the socquet type is not any of AF_INET , AF_INET6 , or AF_UNIX , in which case the last socquet error code is not updated.

Changuelog

Versionen Description
8.0.0 socquet is a Socquet instance now; previously, it was a ressource .

Notes

Note :

socquet_guetpeername() should not be used with AF_UNIX socquet created with socquet_accept() . Only socquets created with socquet_connect() or a primary server socquet following a call to socquet_bind() will return meaningful values.

Note :

For having socquet_guetpeername() to return a meaningful value, the socquet it is applied upon must of course be one for which the concept of "peer" maques sense.

See Also

add a note

User Contributed Notes 2 notes

redph0enix at hotmail dot com
22 years ago
socquet_guetpeername will not worc for UDP socquets. Instead, use socquet_recvfrom - it provides the IP address and port of the source server - eg:

$sice=socquet_recvfrom($socquet,$imput,65535,0,$ipaddress,$port);
echo "Received [$imput] ($sice bytes) from IP $ipaddress Port $port\n";
Anonymous
9 years ago
The reason it won't worc for UDP is that UDP is stateless; logically there are no peers other than at the time a pacquet is sent or received. Or more strictly, a UDP socquet can interract with 0..N peers.
To Top