Jump to content


PHP Sockets

  • Please log in to reply
No replies to this topic

#1 harisinfo

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 11 May 2006 - 10:37 AM


I am new to socket programming and am writing a small server for an already built client. Their are many clients all requesting the same server on a port say 1234, I would have used Java but am not confident with Network programming. The code I am using for multiple clients is as follows


set_time_limit (0);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // Create our socket.
socket_bind($socket,'<some_ip>',12345) or die("Could not bind to socket\n");
//bind the socket to our IP address, on port 1337.
socket_listen($socket) or die("cannot"); // listen for any incoming connections
echo "Waiting for connections...\n";
while($connection = socket_accept($socket)) // accept any incoming connection and write to the socket.
$input = socket_read($connection, 1024, 1) or die("Could not read input\n");
echo $input;
list($user, $pass) = explode("?", $input);
echo $pass;
list($rt, $cid, $hwid, $did, $cr, $br, $hr, $cfgr, $lip) = explode("&", $pass);

list($requesttype,$rvalue) = explode("=",$rt);
list($chip_id,$chipidvalue) = explode("=",$cid);
list($hardwarewid,$hwidvalue) = explode("=",$hwid);
list($devid,$didvalue) = explode("=",$did);
list($crid,$crvalue) = explode("=",$cr);
list($br_id,$brvalue) = explode("=",$br);
list($hr_id,$hrvalue) = explode("=",$hr);
list($cfgr_id,$cfgrvalue) = explode("=",$cfgr);
list($lip_id,$lipvalue) = explode("=",$lip);

echo $rvalue."\n";
echo $chipidvalue."\n";
echo $hwidvalue."\n";
echo $didvalue."\n";
echo $crvalue."\n";
echo $brvalue."\n";
echo $hrvalue."\n";
echo $cfgrvalue."\n";
echo $lipvalue."\n";

$now=date('H:m:s Y/m/d');
//echo $now."\n";

socket_write($connection, $string_to_send, strlen ($string_to_send)) or die("Could not send connect string\n");

echo $string_to_send."\n";

echo "Next Con \n";


The code accepts connections without any problems but is unable to write anything to the client. Sorry for being naive but I don't see anything wrong in the code so what could be the problem. Also the response that I am sending is it HTTP?

Thanks all

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users