3

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!

TheAdmin
  • 78
  • 9

1 Answers1

0

(i cant add a comment yet) first try to set the server ip to '0.0.0.0' and try to use the port 6000 on the server and client and dont use diffrent port and forward diffrent one

Mangisto
  • 59
  • 2
  • Oops I had the port set to 6000 before mustve switched it before posting this on accident. I tried setting the 0.0.0.0 already... I've also screwed around with firewall settings a bunch on our router to try and see if that was the problem but nothing seemed to work... I've never been stuck for this long on a problem lol. – TheAdmin Jun 30 '20 at 23:28
  • When I run client and server on same internet and same pc it wont connect either if I'm using the public ip in the client like shown in examples. – TheAdmin Jun 30 '20 at 23:31