Пример #1
0
def process_received_data(data, address):

    inbound_client_data = data.decode('utf-8').split('->')

    # inbound_client_data[0] je ime klijenta.
    client = nrm.Host(inbound_client_data[0], address)

    if client.name not in Clients:
        Clients[client.name] = client.address

    if client.name not in Requests:
        # inbound_client_data[1] je ime peer-a.
        Requests[client.name] = inbound_client_data[1]

    return client.name
Пример #2
0
def processConnectionRequest(clientName, peerName):

    peer = None

    if clientName in Clients and peerName in Clients:
        peer = nrm.Host(peerName, Clients[peerName])
    else:
        return None

    messageForClient = str.encode('{}:{}'.format(peer.address[0],
                                                 peer.address[1]))
    print('messageForClient: {}'.format(messageForClient))

    Requests.pop(clientName, None)
    return messageForClient
Пример #3
0
            if (data.usr != None) and (data.usr in list(Requests.keys())):
                messageForClient = processConnectionRequest(
                    data.usr, Requests[data.usr])
                if messageForClient != None:
                    # Ako ima potrebne informacije, stavi ih na red za slanje
                    # Oznaci socket kao uspjesno obraden
                    data.outb = messageForClient
                    data.isServed = True


sel = selectors.DefaultSelector()

Clients = {}
Requests = {}

server = nrm.Host('STUN', ('192.168.3.10', 8888))

tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_socket.bind(server.address)
tcp_socket.listen()
tcp_socket.setblocking(False)

sel.register(tcp_socket, selectors.EVENT_READ, data=None)

print('Server slusa...')

try:
    while True:

        events = sel.select(timeout=None)
        for key, mask in events: