Home > Mobile >  How to connect client in a internet to the server
How to connect client in a internet to the server

Time:10-26

I made a simple chat room. But I can't connect clients who joined through internet. I know I'm using local network to this program. But I researched how to connect my server to the internet. I used my Dynamic public IP and port forwarded using my router, but It didn't work. And I used ngrok, but it also didn't work. How can I solve this problem.

This is a part of my program.

IP_Address = 'IP'
Address = (IP_Address,PORT)

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(Address) # Bind IP address and Port to this socket.

When I used my public addressit shows this error.

Traceback (most recent call last):
File "Documents/Projects/Python/server.py", line 13, in <module>
server.bind(Address) # Bind IP address and Port to this socket.
OSError: [Errno 99] Cannot assign requested address

CodePudding user response:

Use server.bind(('',port)) or server.bind(('0.0.0.0',port)). Both mean "bind to all interfaces".

If you want to bind to a specific interface, use your local IP, not the public one. Use ipconfig from the console to see your IP address.

On the router, forward the port to your local IP. Clients on the internet connect to your public IP and port.

CodePudding user response:

I think the best way to solve this problem is using a Cloud Application Platform to run the server program.

  • Related