Forums

how to look for Host and port

I have a snippet from a working script in VPS

# adjust the IP address to reflect the remote location
socket.connect('tcp://134.122.70.51:5555')

# local IP address used for testing
socket.connect('tcp://0.0.0.0:5555')

How to find the local IP and remote IP for Pythonanywhere?

Are you planning to run a raw socket server on PythonAnywhere? Unfortunately that would not be something that we support -- you would not be able to route to it from the external Internet. If you wanted to connect from some other code running inside PythonAnywhere, it might work -- you could use this code to get the internal network address of the currently running process:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
s.close()

...however, it could be different in different consoles, and may change from time to time.