Reputation: 9
This is the server program
# Echo server program
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # 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)
while True:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()
Now, I was wondering if the port i'm using is let us say is 50007 and my friend who is on a uni computer wants to use the client program in order to connect to me. Then does he have to have port 50007 open as well? You know, in order for him to connect to me.
Here is the client program BTW:
import socket
HOST = 'daring.cwi.nl' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall(b'Hello, world')
data = s.recv(1024)
s.close()
print('Received', repr(data)
Upvotes: 0
Views: 554
Reputation: 414159
uni network should allow outgoing tcp connections to port 50007. Your network should allow incoming tcp connections on port 50007.
Upvotes: 1
Reputation: 633
This will work (from a python sockets perspective). When your friend connects to your socket (which is 'open' by virtue of the the .accept() call), that connection will stay open until specifically closed, allowing you to send your message back.
Now, the problem could be the university firewall, which is almost certainly configured to not allow outbound (from him to you) connections on port 50007. If this is the case, unless you have administrator access for the uni firewall you won't be able to connect.
Upvotes: 0