Page 1 of 1

socket_create UDP source port

Posted: Thu Apr 01, 2010 9:52 am
by manu.07
Hello everyone

I'd like to know if it is possible to put a source port
udp packet on create with socket_create.

Code: Select all

 
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
 
$msg = "Message de moi";
$len = strlen($msg);
$ipadd = '192.168.0.1';
$port = '10000';
 
socket_sendto($sock, $msg, $len, 0, $ipadd, $port);
socket_close($sock);

With this code I have port 10000 destination but not source port.

Thank you for your help

Manu.07

Re: socket_create UDP source port

Posted: Thu Apr 01, 2010 1:30 pm
by AbraCadaver
Use stream_socket_server() and then send from that.

Re: socket_create UDP source port

Posted: Thu Apr 08, 2010 1:17 am
by manu.07
Hi

stream_socket_server don't work !

The UDP source port is not fixed.

If your are a new idee?

Tnx

Re: socket_create UDP source port

Posted: Thu Apr 08, 2010 4:03 am
by requinix
If you care about the port then you need to bind to it.

Re: socket_create UDP source port

Posted: Thu Apr 08, 2010 7:48 am
by AbraCadaver
manu.07 wrote:Hi

stream_socket_server don't work !

The UDP source port is not fixed.

If your are a new idee?

Tnx
Sure it is. This listens on 7000 and sends on 7000:

Code: Select all

$socket = stream_socket_server("udp://0.0.0.0:7000", $errno, $errstr);