Xinus Xinus - 2 years ago 107
Python Question

Python SOCK_STREAM over internet

I have a simple programs for socket client and server its not working over internet

# Echo server program
import socket
import ImageGrab

HOST = '' # Symbolic name meaning all available interfaces
PORT = 3000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
conn, addr = s.accept()
print 'Connected by', addr
data = conn.recv(1024)
print data

# Echo client program
import socket
import ImageGrab
#destnation ip
HOST = '' # The remote host
PORT = 3000 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello rushikesh')
print 'Received'#, repr(data)

When we try to make it work over internet it is not able to connect. Program is shown as above only thing is destination ip is replaces by my friends ip.

When working over localhost it works perfectly fine but not working over internet ...

I have written program using
it works over internet only for small chunks of data. I want to transmit image using it so I have written it using
for transmitting image which successfully worked on localhost and was not working over internet. So I did write simplest program but still showing same problem

Can somebody please guid me through this...

Answer Source

You've got the right approach, but you are probably running into networking or firewall problems. Depending on how your friend's networking is configured, he may be behind NAT or a firewall that prevents you from making a direct connection into his computer.

To eliminate half the problem, you can use telnet as a client to make a simple connection to the server to see whether it is available:

telnet 3000

If telnet connects successfully, then the networking works. If it fails, then there is something else wrong (and may give you information that might help discover what).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download