+ 11

Python socket networking problem with IP

Hay friends I am beginner to python networking. And recently working on python socket module. So my question is I had created 2 file 1st). Server.py 2nd). Clint.py and you all know we need a ip to transfer data . I had used the dynamic local ip provided by ISP . Ok . It works fine when I connect my client smart phone with server smartphone through wifi then my interpreter of server ( using pydroid3 ) give the connection of Clint. But when I was trying to acces the same conectiction without wifi but I am using internet instead of wifi . Then I was fail to achieve the same connection. Now I am confused here because the code playground doesn't show any error. So my question is that what should I do . And I dont think that same connection can be done using public IP which Google tells you. So how can I fix it . You can see the source code of clint and server below in answer section. Point to noted : there is no problem with dynamic ip because I always update ip before trying connection.

21st Jun 2020, 3:25 AM
Ayush Kumar
Ayush Kumar - avatar
8 odpowiedzi
+ 8
‐‐‐> Server python code import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = '100.92.12.157' #this is ip port = 1204 s.bind((host,port)) s.listen(1) socketclint , address = s.accept() print("got conection from :",address) con = True while con: msg = socketclint.recv(1024) msg = msg.decode("utf-8") print("clint data :",msg) ap = input("enter msg : ") socketclint.send(ap.encode("utf-8")) if msg == "quit": s.close() con = False ---> Clint python code import socket import os s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = '100.92.12.157' #this is ip port = 1204 s.connect((host,port)) con=True while con: msg = input('enter msg : ') s.send(msg.encode("utf-8")) var=s.recv(1024) var=var.decode('utf-8') print('server data :',var) if msg == 'quit': con = False s.close()
21st Jun 2020, 3:27 AM
Ayush Kumar
Ayush Kumar - avatar
+ 5
Then what else can I do Kuba Siekierzyński sir. I have a way to create a digital server over digital ocean but its paid . And I dont want paid service. Is their any other way also
21st Jun 2020, 9:19 AM
Ayush Kumar
Ayush Kumar - avatar
+ 4
Are you sure your ISP allows such access and there is no firewall in place? This might not be a problem when you are using your own router and access thru Wi-Fi, but outside your local network those two machines are using a connection rules of which may not allow such direct access...
21st Jun 2020, 9:03 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
its has been noted the code promts the re cycle on the run as executed as id as if no error .... found perhaps the bit tyracker is promting the same issue hence its has been taken on consideration... Thanks Regards Sumeet
21st Jun 2020, 10:51 AM
SUMEET SANGAM
SUMEET SANGAM - avatar
+ 1
Url adress
22nd Jun 2020, 11:22 AM
Coder SUXROB :-)
Coder SUXROB :-) - avatar
+ 1
What do you want to say Coder SUXROB :-)
22nd Jun 2020, 3:57 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
port forwarding is the best option maybe your ports are closed
22nd Jun 2020, 9:31 PM
Nishant Tiwari
+ 1
I think you should find out how a router works and routing is implemented. You have to configure a port forwarding in your router which should solve your problem.
22nd Jun 2020, 10:24 PM
Manuel Maier
Manuel Maier - avatar