I'm trying to make a P2P messenger in python, for this I wrote a piece of code that is responsible for finding ip and port for the connection between two clients. I'm not sure that this code works as it should, but in order to find out, I need to upload the script to the server and see what works wrong (There were difficulties with installing and configuring VirtualBox for different ips, and still eventually have to do it). And now I'm completely lost, because, as far as I understand, just pour the script on the hosting and access it on the ip and the port will not work. And I do not understand, is it necessary to fasten some kind of framework, or otherwise contact the hosting? Please help me with all this!
CLIENT CODE
import socket ip = socket.gethostbyname(socket.getfqdn()) port = 9090 input_command = input() if input_command == "connect": print("ID = ") searching_id = input() message_to_Sserver = ip, ",", port, ",", searching_id sock = socket.socket() sock.connect(('198.2255.5225.548', 9090)) print("connected to server") sock.send(message_to_Sserver.encode("utf-8")) print("request send") data = sock.recv() sock.close() udata = data.decode("utf-8") udata = udata.split(",") ip_Client2 = udata[i][0] port_Client2 = udata[i][1] print("conneting to client2") socket.connect((ip_Client2, port_Client2)) print("connection done") else: socket.bind('',9090) socket.listen() SERVER CODE
import socket socket = socket.socket() ALL_ID = [["192.32.32.32", 9090, 1111], ["192.32.32.89", 9030, 2222]] socket.bind(('', 9090)) print(socket.gethostbyname(socket.getfqdn())) print("listening to client") socket.listen() conn, addr = socket.accept() print("connected") while True: data = conn.recv(1024) if not data: break print("request received") udata = data.decode("utf-8") message_from_Client = udata.split(",") ip_Client_wchS1 = message_from_Client[0] port_Client_wchS1 = message_from_Client[1] searching_id_Client = message_from_Client[2] i = 0 while True: i += 1 if searching_id_Client == ALL_ID[i][2]: ip_Client_w0hS2 = ALL_ID[i][0] port_Client_w0hS2 = ALL_ID[i][1] searched_id_Client = ALL_ID[i][2] message_to_Client_wchS1 = ip_Client_w0hS2, ",", port_Client_w0hS2 message_to_Client_whoS2 = ip_Client, ",", port_Client_wchS1 break conn.close() print("connection closed") socket.sendto(message_to_Client_wchS1.encode("utf-8"), ip_Client_wchS1) print("reply to C1") socket.sendto(message_to_Client_whoS2.encode("utf-8"), ip_Client_w0hS2) print("reply to C2") socket.bind(('', 9090)) socket.listen()