PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Wed Feb 07, 2007 5:08 am
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 ??
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Wed Feb 07, 2007 2:07 pm
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, RTS M 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!
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Wed Feb 07, 2007 10:17 pm
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.
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Thu Feb 08, 2007 4:08 am
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?
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Feb 08, 2007 4:15 am
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.
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Thu Feb 08, 2007 4:18 am
Then show us the server code and returned values after each socket_*() call. What did you mean by "No server is answering "?
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Feb 08, 2007 4:23 am
neel_basu wrote: It Showing "220" as on Greeting.
Its Is Showing 220 and Its Correct.
I've Told in The Previous Posts
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Thu Feb 08, 2007 4:43 am
State your problem and give all relevant code. Until you do so nobody can help you.
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Feb 08, 2007 4:57 am
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;
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Thu Feb 08, 2007 5:15 am
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"
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Feb 08, 2007 5:18 am
Ya Its Working Now
But Why " Instead of '
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Thu Feb 08, 2007 5:34 am
neel_basu
Forum Contributor
Posts: 454 Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India
Post
by neel_basu » Thu Feb 08, 2007 5:37 am
Thanks