• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

connect

I was wondering how to connect to a server (eg. router.limewire.com:6346), send a string to the server then print the resonse to the screen?
0
pugandjody
Asked:
pugandjody
  • 3
  • 3
1 Solution
 
pugandjodyAuthor Commented:
I tried using fsockopen, but can't seem to get it right...

I would like to connect to 127.0.0.1:6346, send the string: GNUTELLA CONNECT/0.4\n\n
then take whatever the server sends back and print it to the screen.. could you write that for me?
0
 
pugandjodyAuthor Commented:
Heres what I have:

<?php
$fp = fsockopen("24.209.52.3", 6346, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "GNUTELLA CONNECT/0.4\n\n";

   fwrite($fp, $out);
   while (!feof($fp)) {
       echo fgets($fp, 128);
   }
   fclose($fp);
}
?>

It works fine, it connects, but it doesnt say what the server returns... i need it to write the server's response to the screen.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
snoyes_jwCommented:
Does the script end before timing out?  I've had some problems with some servers not returning an end-of-file character, so the fgets doesn't finish and the while loop is never exited.
0
 
pugandjodyAuthor Commented:
How do I fix the timeout problem?
0
 
snoyes_jwCommented:
First off, make sure the server terminates the string properly.  Second, use stream_set_timeout, so that if it doesn't finish reading within a few seconds, the read attempt ends and the script continues.

http://www.php.net/manual/en/function.stream-set-timeout.php
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now