Aaron_T
Aaron_T

Reputation: 21

Socket Connection Without Knowing Port Number - Python

I would like to create a connection between a server and a client via socket on 2 different computers (but the question is relevant also to a connection on the same computer). I know the IP of the server, but I would like to connect without knowing the port number of the server - is there a way to do so?

for example:

from socket import *

s = socket(AF_INET, SOCK_STREAM)
s.bind((127.0.0.1, " "))
s.listen(1)
conn, addr = s.accept()

Is there a way to do so? Can it also be done without knowing IP?

Upvotes: 1

Views: 2257

Answers (1)

youngminz
youngminz

Reputation: 1444

You can't open a socket without knowing the port number. However, you can use the predefined port numbers in the protocol. For example, if port is not specified, HTTP uses port 80 and HTTPS uses port 443 by default.

Upvotes: 0

Related Questions