Whatever tutorials I've read online dictate how to connect two computers on a local network.
What I want to do is connect my Android phone (I have a terminal emulator on it which has Python installed -- Termux), to my computer.
Server --> Android phone --> Internet
Client --> Computer --> Internet
Client code:
import socket
server_ip = "<My phone's ip which I can google on my phone>"
port = 9999
s = socket.socket()
s.connect((server_ip, port))
s.send(str.encode("Hello there!", 'utf-8'))
s.close()
Server code:
import socket
s = socket.socket()
s.bind(('', 9999))
s.listen(1)
conn, addr = s.accept()
print( str(conn.recv(1024), 'utf-8') )
The thing is, if I try this, I get the TimeoutError.
(PC-side code)
>>> import socket
>>> s = socket.socket()
>>> s.connect(('72.128.66.21', 9999))
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
s.connect(('72.128.66.21', 9999))
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
It looks like the IP I entered was wrong, so I re-checked it, it wasn't. The server was hosted on that IP and port.
Also, I don't think Termux is like some sort of virtual environment, so the server should actually be publicly accessible.
EDIT: If this is of any help, I am using portable hotspot of another phone as an access to the Internet, so it's acting like a router.
EDIT 2: Also, I tried doing telnet myPhone'sIP portNo and it failed.