This is my code for server :
import socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "192.168.1.3"
port = 8000
print (host)
print (port)
serversocket.bind((host, port))
serversocket.listen(5)
print ('server started and listening')
while 1:
(clientsocket, address) = serversocket.accept()
print ("connection found!")
data = clientsocket.recv(1024).decode()
print (data)
clientsocket.send("data is sent".encode())
and for Client :
import socket
s = socket.socket()
host ="59.93.199.XXX"
port =8000
s.connect((host,port))
s.send('randomData'.encode())
data = ''
data = s.recv(1024).decode()
print (data)
s.close
I want this to work across two computers across the internet. when I put host="192.168.1.3" in client, it works fine, but that's only for computers connected to the same network. The thing is, that while server is running, and i check for open port online,the server shows 'connection found', but it does not connect to server via client. what am i doing wrong ? PORT 8000 is open.
192.168.1.3 is my computer's IP and 192.168.1.1 is the gateway ERROR THAT I GET WHEN I RUN CLIENT :
Traceback (most recent call last): File "C:\Users\Harsh's\Desktop\aaa.py", line 6, in s.connect((host,port)) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it