Re: fsockopen - how can I specify the local/source port

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, April 18, 2007 5:48 am, Matt wrote:
> I am experimenting with the fsockopen function to send custom UDP
> packets.
> What I would like to do is to be able to nominate the LOCAL port that
> my UDP
> packet originates from. What happens currently is that when I execute
> my
> code below I get a random port >1023 allocated. What I want to be able
> to do
> is to fix the port to one that I specify.
>
> The code below works and I can see my packet being sent out to
> destination
> port 7077.  The 192.168.2.10 server is also watching for the source
> port of
> incoming traffic and will only respond if the source port is also
> 7077.
>
> <?php
> $fp = fsockopen("udp://192.168.2.10", 7077, $errno, $errstr);
> if (!$fp) {
>     echo "ERROR: $errno - $errstr<br />\n";
> } else {
>     fwrite($fp, "Test\n");
>     echo fread($fp, 26);
>     fclose($fp);
> }
> ?>
>
> Any ideas how I can achieve this?

I believe you can only get what you want by dropping down to the lower
level socket stuff:
http://php.net/sockets

There may be some new-fangled streams stuff that also does it, with
"prettier" code...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux