2

I am using Mobile Hotspot with configurations Security:WPA2-Personal and AP Band:2.4GHz-band.

Server code:

import socket
s = socket.socket()
print ("Socket successfully created")
s.bind(("0.0.0.0", 9999)) # xxxx also does not work
# xxx=external ip address returned by https://checkip.amazonaws.com/

s.listen(3)
print("waiting for connections...")

while True:
    print ("Entered while loop!!!")
    flag = input("Stop: ")
    if flag == "y":
        break
    # Establish connection with client.
    c, addr = s.accept()    
    print ('Got connection from', addr )

    # send a thank you message to the client. encoding to send byte type.
    c.send('Thank you for connecting 9433'.encode())

    # Close the connection with the client
    c.close()
    flag = input("Stop: ")
    if flag == "y":
        break

Client Code:

# Import socket module
import socket           

# Create a socket object
s = socket.socket()     

# Define the port on which you want to connect
port = 9999         

# connect to the server on local computer
s.connect(('xxxx', port)) # xxxx=external ip address returned by https://checkip.amazonaws.com/ 

# receive data from the server and decoding to get the string.
print (s.recv(1024).decode())
# close the connection
s.close()

What I want to achieve

Let's say I have started the server in one of my computer(note:moblie hotspot connected). My other computer is in another apartment connected to another mobile hotspot. I want them to communicate in all ways possible- such as checking battery level, asking to create a folder or file, sending or receving file, etc. In all of this, my laptop acts like a server and the other PC always keep checking if the server is running. If runing, it connects to my laptop

Current Problem

I can do this communication using localhost. But cannot do it in two completely seperate Pcs.
I am getting the error Win 10060 in my current code.


Please note: The above code is in its simplest form and I am just trying to establish the connection so that I can send and receive data. After that I will modify it.
If My approach is wrong or there is conceptual problem, please write in the comments.

Curious Learner
  • 1,182
  • 1
  • 4
  • 17
  • In short: it is not trivial since both systems are in restricted environments and likely also private network address space. One need to use outside helpers accessible from both sides to establish a connection or even to transfer the data. Keywords are STUN, TURN, ICE. – Steffen Ullrich Dec 18 '21 at 07:54

0 Answers0