473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with sockets needed

Hello all!

I need some help with sockets. I have this code:

$Connection = fsockopen( "google.com", 80, $ErrNo, $ErrStr, 30 );

if($Connection){

echo "Connection established\n";

while(!feof($Connection)){

echo fgets($Connection, 128);

}

echo "Got some data\n";

} else {

echo "Error $ErrNo: $ErrStr\n";

}

But it never gets to output anything, it only prints "Connection
established" and then the script simply gets stuck, it never gets to
say "Got some data"...

Any help will be very appreciated.
Thanks,

Artemiy.

Sep 15 '06 #1
3 1019

ar*****@kdemail.net wrote:
echo fgets($Connection, 128);
[...]
But it never gets to output anything
That is because google.com does not send anything. Only after you sent
a request will google.com respond. The fgets waits for ever for a line
from google.com.

Sep 15 '06 #2
Hello and thanks for your reply!

Oh sorry, yes, with HTTP it indeed is like this, but here is an example
for POP3:

$Connection = fsockopen( "soniccharger.com", 110, $ErrNo, $ErrStr, 30
);

if($Connection){

echo "Connection established\n";

while(!feof($Connection)){

echo fgets($Connection, 128);

}

echo "We got some data\n";

} else {

echo "Error $ErrNo: $ErrStr\n";

}

When I run it I get:

$ php pop3test.php
Connection established
+OK Hello there.

And then it gets stuck... :-/

Sep 15 '06 #3
*** ar*****@kdemail.net escribió/wrote (15 Sep 2006 11:01:41 -0700):
When I run it I get:

$ php pop3test.php
Connection established
+OK Hello there.

And then it gets stuck... :-/
Same as with your Google example, I presume. The POP3 server is awaiting
your commands.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Sep 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Julia Goolia | last post by:
hello, i read that it is bad to use threads with tkinter. so my question is how does one create a gui program with sockets? at one point you have to call mainloop() which does not return. ...
0
by: Gonçalo Rodrigues | last post by:
Hi, I have a problem with threads and sockets. I'll try to describe the problem in words with pseudo-code. I've been working on a few classes to make it easier to work with threads. This...
4
by: Garam | last post by:
I need to write a substantial amount of network code in C. The thing is, it has to be able to run on both Unix and Windows. Rather than writing separate code for each, I was looking for something...
0
by: Eternal Snow | last post by:
Hello. I have some trouble. Please look at this code below written in VB2005 (.net 2 50727). Sub Main() Dim osck As Net.Sockets.Socket Dim datagram() As Byte = {69, 0, 0, 52, 108, 180, 0, 0,...
4
by: radiax | last post by:
Is there a way to associate or bind a subdomain to a tcp sockets under .net framework (vb.net / c#). I know ip address can be used when using sockets, but the problem is the ip address is shared...
4
by: Funke | last post by:
Assume that in C#, I create a server socket (listener) and code to start new threads with each connection using BeginAccept(). After some time, I have three threads running, each with their own...
0
by: john.kramer | last post by:
I need a VB.NET app that allows me to connect to a device using telnet, send two commands (the second of which terminates the connection), then confirm that the connection is terminated. If I...
5
by: ibid | last post by:
hi every one just wondering if anyone could help sorry if i seem abit dumb but im a newbie to it all ive got to asign a mail program on my auction site in the config.pl files (i think this is the...
25
by: 4.4.bsd | last post by:
Is there any possible way to use sockets in C, so i can finish a instant messenger program?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.