Jump to content

harisinfo

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

harisinfo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, 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"); $input=trim($input); echo $input; list($user, $pass) = explode("?", $input); $pass=trim($pass); 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"; $string_to_send="currenttime=$now\ncoderevision=3.95.02\ncodefile=none\nbootrevision=3.67.01\nbootfile=none\ncfgrevision=3.67.00\ncfgfile=none\nspecial=none\nloader=none"; 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.