Jump to content

Errors in socket program


cherankrish

Recommended Posts

Hi All,

This is my simple socket program.It works fine on my local computer. (assume i've changed the ip address in remote) But when i upload this to my remote computer it stops work.i could open the port but it closes suddenly. couldn't read the port.when i tel net to that port ,it opens but closing suddenly.

 

My remote server  is redhat 4.1.2.what would be the problem.im stuck.

 

 

 

 

 

 

<?php

 

$sock_comingno = '0384902635';

$cfgServer   = "10.192.0.93"; 

$cfgPort      = "3575";         

$cfgTimeOut = "100";

$usenet = @fsockopen($cfgServer, $cfgPort, &$errno, &$errstr, $cfgTimeOut);

 

 

if(!$usenet)

      {

      echo "Connection failed\n";

      exit();

      }

else

      {

echo 'connected    ';

      fputs ($usenet, "BAL $sock_comingno");

  $result = fgets($usenet, 2048);

sleep(5);

echo $result."\n\r  ";

 

 

$result = fgets($usenet, 2048);

echo $result;

echo $result."  ";

 

 

 

 

 

 

 

fclose($usenet);

//die();

 

 

 

 

 

 

             

 

      }

 

 

 

fclose($usenet);  

 

?>

Link to comment
https://forums.phpfreaks.com/topic/171584-errors-in-socket-program/
Share on other sites

$usenet = @fsockopen($cfgServer, $cfgPort, &$errno, &$errstr, $cfgTimeOut);

 

Should be:

 

$errno = 0;
$errstr = '';
$usenet = @fsockopen($cfgServer, $cfgPort, &$errno, &$errstr, $cfgTimeOut);

 

Change:

 

echo "Connection failed\n";

 

To:

 

echo $errno, ': ', $errstr;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.