?
Solved

connect

Posted on 2005-03-25
6
Medium Priority
?
162 Views
Last Modified: 2012-06-21
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
Comment
Question by:pugandjody
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 375 total points
ID: 13633829
0
 

Author Comment

by:pugandjody
ID: 13634014
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
 

Author Comment

by:pugandjody
ID: 13634106
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
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.

 
LVL 33

Expert Comment

by:snoyes_jw
ID: 13637109
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
 

Author Comment

by:pugandjody
ID: 13637692
How do I fix the timeout problem?
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 13640417
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question