Page 1 of 1

fsockopen does not work from web client pages

Posted: Tue Jan 28, 2014 2:31 am
by markelliot123
[text]The following code sends out a UDP packet when I run it from my Linux server with the address of my web client udp://192.168.1.107:2159. However, when I call the same web page from the client with the address Linux server address shown in the code, NO UDP packet is emitted. I tried both a PC client with chrome and a Mac client with Safari. Also the phpinfo() shows that allow_url_fopen is "On". Also, I tried the code without the fflush() function too. Is there restrictions on Client web pages and PHP sockets? I don't see this searching the net. By the way, I coded a Java app on the same client machine and it sends the UDP packet to the address and port without problem.[/text]

Code: Select all

phpinfo();

$errno = 0;
$errstr = "";
$fsocket = fsockopen("udp://192.168.1.103:2195", $errno, $errstr);
if( !$fsocket ) {
  echo "$errstr( $errno)<br/>\n";
} else {
  $out = "Oh ya baby!\r\n";
  fwrite( $fsocket, $out );
  fflush( $fsocket );
  fclose($fsocket);
}
[/text]

Re: fsockopen does not work from web client pages

Posted: Tue Jan 28, 2014 1:03 pm
by requinix
markelliot123 wrote:However, when I call the same web page from the client with the address Linux server address shown in the code, NO UDP packet is emitted.
So... that code you posted, you put it in a web page and browsed to that page? I don't see any reason it would fail, but at the very least you should get one of those output messages. Did you?

Re: fsockopen does not work from web client pages

Posted: Tue Jan 28, 2014 1:36 pm
by markelliot123
The code does not show any failure messages. It acts as if it worked. However, I do not see the packet on the wire.

Re: fsockopen does not work from web client pages

Posted: Tue Jan 28, 2014 2:09 pm
by requinix
Can you switch to TCP and see if the packet is transmitted? I'd imagine not but it'd be nice to confirm that.

Re: fsockopen does not work from web client pages

Posted: Mon Feb 03, 2014 9:45 pm
by markelliot123
Yes I did try TCP too. I also tried putting the port address as the second parameter and setting a timeout.

Code: Select all

$fsocket = fsockopen("udp://192.168.1.108", 2195, $errno, $errstr, 30);
$fsocket = fsockopen("udp://192.168.1.103:2195", $errno, $errstr);
$fsocket = fsockopen("tcp://192.168.1.103:2195", $errno, $errstr);

Re: fsockopen does not work from web client pages

Posted: Tue Feb 04, 2014 9:06 pm
by markelliot123
The issue... You can't always believe Wireshark! I trusted Wireshark too much. I created a Java application to receive from the Web based PHP fsockopen packet transmission. Low and behold, Java catches the packet and Wireshark missed the packet - every time too. The Wireshark case that failed was Mac (client PHP web call), Linux (Wireshark session and PHP web server).

I don't know if Wireshark labels the packet as something else or there is something obscure in the PHP generated packet as far a Wireshark is concerned? The weird thing is when I transmit the same packet from a Java application Wireshark catches it! I do not know all the reasons why. But I got PHP fsockopen to work so my job is done! It works between Linux and Mac OS 10 in all combinations of client and server, so great!