Beispiel #1
0
    def handle(self, *args, **options):
        # Get node ID
        node_id = int(args[0])

        # Create socket
        client_socket = socket(AF_INET, SOCK_STREAM)
        # Connect to host on specified port
        client_socket.connect(('127.0.0.1', server_port()))

        # Try to contact server
        try:
            sendMsg(client_socket, str(node_id))
        except:
            abnormalShutdown(client_socket, "Error")

        # Shut down write side of socket
        client_socket.shutdown(1)

        # Receive incoming message from server
        try:
            response = recvMsg(client_socket)
        except:
            print "Could not receive message from server"

        # Close socket
        client_socket.close()
        return response
Beispiel #2
0
def get_node_status(node_id):
    # Create socket
    clientSocket = socket(AF_INET, SOCK_STREAM)
    # Connect to localhost on specified port
    clientSocket.connect(('127.0.0.1', server_port()))
    # Print connection information to console
    #print("Connected to " + str(clientSocket.getpeername()[0]) + " on port " + str(server_port()))

    try:
        sendMsg(clientSocket, str(node_id))
    except:
        abnormalShutdown(clientSocket, "Error")
                    
    # Shut down write side of socket
    clientSocket.shutdown(1)
    
    # Receive incoming message from server
    return recvMsg(clientSocket)
    #print("Received from server " + str(incomingMsg))
    # Close socket
    clientSocket.close()