I am trying to make it so that i can connect to this server from other networks around the world, as you see on the screenshot provided i have port-forwarding set up to forward all request on external port 6000 to my static ip address stored in the host variable.
#This is my Server
import socket
import threading
host = '192.168.1.135'
port = 6000
#s = socket.socket()
s = socket.socket()#socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen()
def send():
mess = input("--> ")
con.send(bytes(mess, 'utf-8'))
def receive():
msg = con.recv(1024)
print(msg.decode('utf-8'))
while True:
try:
con, address = s.accept()
print(f'Connection to {address} made successfully!')
receive()
send()
except:
pass
This is my client file below, i took out my public ip address from the host variable for obvious reasons... When i try connecting while connected to the network the server is running on it joins fine, in the server file where it prints the ip address it shows my networks gateway address as the connected ip. But when when trying to connect from outside the network it doesn't work!
import socket
host = 'public ip'; port = 6000
def send():
mess = input('--> ')
s.send(bytes(mess,"utf-8"))
def receive():
msg = s.recv(1024)
print(msg.decode('utf-8'))
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, port))
send()
receive()
except:
pass
This link will show you a picture of the settings i have set in my network settings.
https://i.stack.imgur.com/TmNYc.png
I am pretty new to the whole "port-forwarding" idea but cannot seem to find the issue after over a week of trying hundreds of solutions nothing seems to work... If you need any more information to help in solving this just ask, thank you!