PHP 8.1.28 Released!

socket_getpeername

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

socket_getpeernameBelirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür

Açıklama

socket_getpeername(Socket $soket, string &$adres, int &$port = null): bool

Belirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür.

Bağımsız Değişkenler

soket

socket_create() ile oluşturulmuş geçerli bir Socket nesnesi.

adres

Belirtilen soket AF_INET veya AF_INET6 türündeyse socket_getsockname() işlevi, bu bağımsız değişkende bir IP adresi (127.0.0.1 veya fe80::1 gibi) ve port bağımsız değişkeninde de belirtilmişse ilgili port numarasını döndürür.

Belirtilen soket AF_UNIX türündeyse bu bağımsız değişkende (/var/run/daemon.sock gibi) bir Unix dosya yolu döner.

port

Belirtilmişse ilgili port değeri bu bağımsız değişkene konur.

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner. Soket AF_INET, AF_INET6 veya AF_UNIX türünde değilse işlev false döndürebilir, ancak böyle bir durumda son soket hata kodu güncellenmez.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0soket artık bir Socket örneği olabiliyor; evvelce resource türündeydi.

Notlar

Bilginize:

socket_getpeername() işlevi socket_connect() ile oluşturulan AF_UNIX soketlerle kullanılmamalıdır. Sadece socket_accept() ile oluşturulan soketler ve socket_bind() çağrısından sonra bir birincil sunucu soketi için anlamlı bir değer döner.

Bilginize:

socket_getpeername() işlevinin anlamlı bir değer döndürmesi için, uygulandığı soket, "çift" kavramının anlamına uygun bir soket olmalıdır.

Ayrıca Bakınız

  • socket_getsockname() - Belirtilen soketin yerel tarafını sorgulayıp soket türüne göre ya bir konak/port çifti ya da bir Unix dosya yolu döndürür
  • socket_last_error() - Soket üzerindeki son hatanın kodunu döndürür
  • socket_strerror() - Bir soket hatasıyla ilgili açıklamayı döndürür

add a note

User Contributed Notes 2 notes

up
3
Anonymous
8 years ago
The reason it won't work for UDP is that UDP is stateless; logically there are no peers other than at the time a packet is sent or received. Or more strictly, a UDP socket can interact with 0..N peers.
up
3
redph0enix at hotmail dot com
20 years ago
socket_getpeername will not work for UDP sockets. Instead, use socket_recvfrom - it provides the IP address and port of the source server - eg:

$size=socket_recvfrom($socket,$input,65535,0,$ipaddress,$port);
echo "Received [$input] ($size bytes) from IP $ipaddress Port $port\n";
To Top