P
P
Popchik2017-10-13 01:26:37
Python
Popchik, 2017-10-13 01:26:37

How to upload python signal server script to hosting?

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 a connection between two clients. I'm not sure if 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 under different ip, and anyway in eventually you have to do it).
And now I'm completely lost, because, as far as I understand, just uploading the script to the hosting and accessing it by IP and port will not work. And I don’t understand, do I need to screw some kind of framework here, or do I need to contact hosting in a different way? Please help me figure this all out!
CLIENT

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
import socket

socket = socket.socket()
ALL_ID = 

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()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question