Reputation: 30533
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))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
data = conn.recv(1024)
print data
conn.close()
# Echo client program
import socket
import ImageGrab
#destnation ip
HOST = '127.0.0.1' # 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')
s.close()
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 SOCK_DGRAM
it works over internet only for small chunks of data. I want to transmit image using it so I have written it using SOCK_STREAM
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...
Upvotes: 2
Views: 5517
Reputation: 993861
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 127.0.0.1 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).
Upvotes: 5