Ejemplo n.º 1
0
def handler(sc, address):
    messageLength = int(sc.recv(MESSAGE_LENGTH_DIGITS))
    networkMessage = sc.recv(messageLength)
    messageHead = networkMessage[0:MESSAGE_HEAD_LENGTH]
    message = networkMessage[(MESSAGE_HEAD_LENGTH + 1):]  # +1 for delimiter

    if messageHead == SERVERINFO:
        Slave.saveServerInfo(message)
    elif messageHead == GRAPH:
        Slave.saveGraph(message)
    elif messageHead == PUSHTASK:
        main.pushTaskToQueue(message)
    elif messageHead == STARTPROCESSING:
        Slave.startProcessing(message)
    elif messageHead == REQUESTTASK:
        response = main.grantTask()
        network.send(sc, response)
    elif messageHead == SENDPARTIALRESULT:
        response = Slave.getPartialResult(message)
        network.send(sc, response)
    elif messageHead == HASHCHECK:
        response = main.checkHash(message)
        network.send(sc, response)
    elif messageHead == PING:
        Slave.recordPing(message)
        network.send(sc, PONG)
    elif messageHead == NETWORKPRIME:
        Slave.saveNetworkPrime(message)
    else:
        Slave.unrecognizedMessage(message)

    sc.close()
Ejemplo n.º 2
0
def handler(sc, address):
    messageLength = int(sc.recv(MESSAGE_LENGTH_DIGITS))
    networkMessage = sc.recv(messageLength)
    messageHead = networkMessage[0:MESSAGE_HEAD_LENGTH]
    message = networkMessage[(MESSAGE_HEAD_LENGTH + 1):] # +1 for delimiter

    if messageHead == SERVERINFO:
        Slave.saveServerInfo(message)
    elif messageHead == GRAPH:
        Slave.saveGraph(message)
    elif messageHead == PUSHTASK:
        main.pushTaskToQueue(message)
    elif messageHead == STARTPROCESSING:
        Slave.startProcessing(message)
    elif messageHead == REQUESTTASK:
        response = main.grantTask()
        network.send(sc, response)
    elif messageHead == SENDPARTIALRESULT:
        response = Slave.getPartialResult(message)
        network.send(sc, response)
    elif messageHead == HASHCHECK:
        response = main.checkHash(message)
        network.send(sc, response)
    elif messageHead == PING:
        Slave.recordPing(message)
        network.send(sc, PONG)
    elif messageHead == NETWORKPRIME:
        Slave.saveNetworkPrime(message)
    else:
        Slave.unrecognizedMessage(message)

    sc.close()
Ejemplo n.º 3
0
def handler(sc, address):
    messageLength = int(sc.recv(MESSAGE_LENGTH_DIGITS))
    networkMessage = sc.recv(messageLength)
    messageHead = networkMessage[0:MESSAGE_HEAD_LENGTH]
    message = networkMessage[(MESSAGE_HEAD_LENGTH + 1):] # +1 for delimiter

    if messageHead == GETSERVERINFO:
        response = Master.getServerListNetString()
        network.send(sc, response)
    elif messageHead == INPUT:
        Master.processInput(message)
    elif messageHead == HEARTBEAT:
        Master.recordHeartBeat(message)
    elif messageHead == PING:
        Master.recordPing(message)
        network.send(sc, PONG)
    elif messageHead == PARTIALRESULT:
        Master.processPartialResult(message)
    elif messageHead == JOBCOMPLETE:
        Master.recordJobCompleteNotification(message)
    else:
        Master.unrecognizedMessage(message)

    sc.close()