Page 1 of 1
socket_read() Timeout
Posted: Wed Feb 07, 2007 5:08 am
by neel_basu
Code: Select all
................
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,'localhost',25);
$greet = socket_read($socket, 1024);
echo $greet;
.................
This above Code Works And Shows The Greeting Messege Where as.
This Following Code Is making time out nothing else . It is Not Showing The Reply.
Code: Select all
....................
echo socket_write($socket,$text.'\r\n',strlen($text)+2)."<br />\n";
$reply = socket_read($socket, 1024);
echo $reply;
.........................
But This Code
Code: Select all
...................
echo socket_write($socket,$text.'\r\n',strlen($text)+2)."<br />\n";
//$reply = socket_read($socket, 1024);
//echo $reply;
.....................
Shows Result 16
any solutions ??
Posted: Wed Feb 07, 2007 2:07 pm
by Mordred
It looks like the server is not answering anything.
Show the server code that replies to that message.
Maybe it expects a zero-terminated string? In any case you can safely omit the third parameter of socket_write.
Also, you gotta make sure all functions succeeded, check the return values after each call, RTSM for details.
P.S. In the English language you're not expected to capitalise every word of the sentence, the first one and the occasional name and "I" are enough!
Posted: Wed Feb 07, 2007 10:17 pm
by neel_basu
It Showing "220" as on Greeting.
Mordred wrote:It looks like the server is not answering anything.
No server is answering . fread can read it and if i use fread() in the place of socket_read() it works smoothly.
Mordred wrote:Maybe it expects a zero-terminated string? In any case you can safely omit the third parameter of socket_write.
No It accepts \r\n Terminated Strings.
Posted: Thu Feb 08, 2007 4:08 am
by Mordred
No server is answering . fread can read it and if i use fread() in the place of socket_read() it works smoothly.
fread() can read from a file or a socket.
socket_read() can only read from a socket.
What are you trying to do here?
Re: socket_read() Timeout
Posted: Thu Feb 08, 2007 4:15 am
by neel_basu
neel_basu wrote:Code: Select all
................
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,'localhost',25);
$greet = socket_read($socket, 1024);
echo $greet;
.................
Obviously from a socket.
Posted: Thu Feb 08, 2007 4:18 am
by Mordred
Then show us the server code and returned values after each socket_*() call. What did you mean by "No server is answering"?
Posted: Thu Feb 08, 2007 4:23 am
by neel_basu
neel_basu wrote:It Showing "220" as on Greeting.
Its Is Showing 220 and Its Correct.
I've Told in The Previous Posts
Posted: Thu Feb 08, 2007 4:43 am
by Mordred
State your problem and give all relevant code. Until you do so nobody can help you.
Re: socket_read() Timeout
Posted: Thu Feb 08, 2007 4:57 am
by neel_basu
I am writting it again
neel_basu wrote:Code: Select all
................
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,'localhost',25);
$greet = socket_read($socket, 1024);
echo $greet;
.................
This above Code Works And Shows The Greeting Messege Where as.
This Following Code Is making time out nothing else . It is Not Showing The Reply.
Code: Select all
....................
echo socket_write($socket,$text.'\r\n',strlen($text)+2)."<br />\n";
$reply = socket_read($socket, 1024);
echo $reply;
.........................
But This Code
Code: Select all
...................
echo socket_write($socket,$text.'\r\n',strlen($text)+2)."<br />\n";
$reply = socket_read($socket, 1024);//Timeout Happens For This Line
echo $reply;//Actually It Shoul Show 250
.....................
Shows Result 16
any solutions ??
Look
Code: Select all
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($socket,'mail.bluebottle.com',25);
$greet = socket_read($socket, 1024);//This socket_read() Works and Sockets Replies With 220
echo $greet;//It Also Works And Shows The Reply Text With 220 Code
//220 fe1.bluebottle.com ESMTP Sendmail 8.13.1/8.13.1; Thu, 8 Feb 2007 02:54:38 -0800
$text = "HELO localhost";
echo socket_write($socket,$text.'\r\n',strlen($text)+2)."<br />\n"; //This Also Works and returns 26
$reply = socket_read($socket, 1024); //But This Line Doesn't Work Just Makes Timeout Nothing else
echo $reply;
Posted: Thu Feb 08, 2007 5:15 am
by Mordred
Ah, you're connecting to an existing remote server. As I said before, the server isn't answering, that's why your read fails.
I finally see the reason why: '\r\n' should be "\r\n"
Posted: Thu Feb 08, 2007 5:18 am
by neel_basu
Ya Its Working Now
But Why " Instead of '
Posted: Thu Feb 08, 2007 5:34 am
by Mordred
Posted: Thu Feb 08, 2007 5:37 am
by neel_basu
Thanks