I tried to run following program on my Mac terminal.
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.py4inf.com', 80))
mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n')
while True:
data = mysock.recv(512)
if ( len(data) < 1 ) :
break
print data;
mysock.close()
But it doesn't print anything and takes forever. I tried some online platform to execute and got error message
"""Traceback (most recent call last): File "main.py", line 6, in mysock.connect(('www.py4inf.com', 80)) File "/usr/lib64/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 110] Connection timed out"""
I put print statement after True: and before line "data = " and it prints statement there and then takes forever.
My Python environment is
"Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin"
And in different computer, it works.
Can anybody identify an issue?