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.
(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)
socket_getpeername — 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
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.
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.
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: | Açıklama |
---|---|
8.0.0 | soket artık bir
Socket örneği olabiliyor; evvelce
resource türündeydi. |
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.
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.
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";