Socket problem

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I'm writing a php script that sends data and receives data from a server. The first few sends and receives work fine, and then if I want to sent data the script (actually the socket) hangs for one minute and then the socket is closed. Does anybody know what might be wrong, or what could be causing this?
 
Sorry for not posting the code, i fixed my problem...
I had (this is in a class):
Code:
<?php

function Send($data)
{
         if (!feof($this->socket))
         {
                    fputs($this->socket, $data);
         }
}

if ($this->socket = fsockopen("127.0.0.1", 8000))
{
          $this->Send("aaa\r\n");
          $this->Send("bbb\r\n");  
          $this->Send("ccc\r\n");
          $this->Send("ddd\r\n"); //hangs and then closes socket 
}

?>
I don't know why, but when I removed the if statement to check whether the socket is still open in the "Send" function everything worked fine.
 
I don't know why, but when I removed the if statement to check whether the socket is still open in the "Send" function everything worked fine.
you could just do...
Code:
if ($this->socket)
{
   ....
}
 
Back
Top