tags:

views:

292

answers:

1

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...

+4  A: 

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).

Greg Hewgill
Hi, telnet connection fails. But p2p communication using SOCK_DGRAM is working properly and gives me chat like functionality and also works for small images. Is it the case that SOCK_STREAM requires a connection and SOCK_DGRAM works via some different mechanism ..
Xinus
We do not have any proxy or NAT in between. We have a general broadband connection from isp. We do not have static ip . Can it be the reason ? But then how SOCK_DGRAM is working. May be SOCK_DGRAM do not require static ip ?
Xinus
Maybe the server-side isp is blocking listening(server) TCP sockets? If you start a web server there, does it work over internet?
macbirdie
What can be the way to achieve it? I tried twisted Datagram server client but it still do not work over internet. p2p programs like C-space http://cspace.in/ can transmit binary files over internet and works on my pc
Xinus
I think your next approach should be to use something like `tcpdump` or whatever an equivalent network sniffer is for your OS. Find out whether the packets in question are actually making it from point A to point B.
Greg Hewgill