PHP: socket_recvfrom - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

socket_select socket_recv

Last updated: Fri, 26 Jan 2007

view this page in

# socket_recvfrom

(PHP 4 >= 4.1.0, PHP 5)

socket_recvfrom -- Receives data from a socket, connected or not

## Description

int socket_recvfrom ( resource socket, string &buf, int len, int flags, string &name [, int &port] )

Внимание
К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

socket_recvfrom() has been binary safe since PHP 4.3.0

add a note User Contributed Notes
socket_recvfrom
aeolianmeson at xxxxx dot blitzeclipse dot com
24-Nov-2006 07:42
`The IP will be returned (-1) if no data was received.
Dustin Oprea`
ryan_at_ryanfisher_dot_com
01-Oct-2006 10:27
`DNS RELAY USING UDP SOCKETS
<?php
while(TRUE) {
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if($socket === FALSE)
{
echo 'Socket_create failed: '.socket_strerror(socket_last_error())."\n";
}
if(!socket_bind($socketD, "0.0.0.0", 53)) {
socket_close($socketD);
echo 'socket_bind failed: '.socket_strerror(socket_last_error())."\n";
}
socket_recvfrom($socket,$buf,65535,0,$clientIP,$clientPort);
$stz = bin2hex($buf);
$tx = "";
for($i=0;$i<(strlen($stz)-26-10)/2;$i++)
{
$e = "00";
$e[0] = $stz[$i*2+26];
$e[1] = $stz[$i*2+27];
$f = hexdec($e);
if($f > 0 && $f < 32) $tx .= "."; else
$tx .= sprintf("%c",$f);
}
echo "$clientIP <".$tx.">\n";
$fp = fsockopen("udp://72.174.110.4",53,$errno,$errstr);
if (!$fp)
{
echo "ERROR: $errno - $errstr<br />\n";
}
else
{
fwrite($fp,$buf);
$ret = $buf;
$ret = fread($fp,667);
fclose($fp);
}
}
socket_send($socket,$ret,667,0);
}
?>`
tsuna at tsunaquack d0t c0m
21-Feb-2005 03:17
`This function is very handy when dealing with UDP connections, because it enables you to know who's the client who connected to your socket. Bear in mind that UDP doesn't care about the source of the connection, the packets may be annonymous or even faked. No check is required.
If you want to listen on an UDP socket and answer to the client, read my comment on socket_listen() -> http://www.php.net/manual/en/function.socket-listen.php`
add a note
socket_select socket_recv

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST