socket_create UDP source port

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manu.07
Forum Newbie
Posts: 2
Joined: Thu Apr 01, 2010 9:27 am

socket_create UDP source port

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: socket_create UDP source port

Post by AbraCadaver »

Use stream_socket_server() and then send from that.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
manu.07
Forum Newbie
Posts: 2
Joined: Thu Apr 01, 2010 9:27 am

Re: socket_create UDP source port

Post by manu.07 »

Hi

stream_socket_server don't work !

The UDP source port is not fixed.

If your are a new idee?

Tnx
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: socket_create UDP source port

Post by requinix »

If you care about the port then you need to bind to it.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: socket_create UDP source port

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply