sockets - Using PHP broadcast to detect Server IP address -
i want article: broadcast detect server ip address
and transfer php, possible?
the reason want send broadcast socket server, , server return message can determine message want or not detect true ip of message sender.
the code like:
<?php error_reporting(e_all); $address = "255.255.255.255"; $port = 10000; /* create udp socket. */ $socket = socket_create(af_inet, sock_stream, sol_tcp); if ($socket === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br/>"; } else { echo "socket created.<br/>"; } echo "attempting connect '$address' on port '$port'..."."<br/>"; $result = socket_connect($socket, $address, $port); if ($result === false) { echo "socket_connect() failed.\nreason: ($result) " . socket_strerror(socket_last_error($socket)) . "<br/>"; } else { echo "successfully connected $address."."<br/>"; } $i="themessage"; echo "sending $i server."."<br/>"; socket_write($socket, $i, strlen($i)); $input = socket_read($socket, 512); echo "response server is: $input"."<br/>"; $ip=""; if($input=="i want") $ip=socket_send_from_the_ip; // psuedocode echo "closing socket..."; socket_close($socket); ?>
or direction of question wrong? think should use httprequest?
any answer appreciated.
Comments
Post a Comment