예제 #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
예제 #2
0
파일: client.py 프로젝트: rlacherksu/ccasp
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()
예제 #3
0
파일: server.py 프로젝트: rlacherksu/ccasp
    # Create socket object
    socket = socket(AF_INET, SOCK_STREAM)
    # Bind socket to localhost on defined port
    socket.bind(('', server_port()))
    # Start listening
    socket.listen(0)
    
    while True:
        # Accept connections while server is alive
        conn, address = socket.accept()
        
        # Print connection information
        #print("Connection received from client address " + str(address[0]) + " on port " + str(address[1]))
        
        # Try to receive incoming message and starting time
        incomingMsg = recvMsg(conn)
        # Print message from client
        #print("Received from client: " + str(incomingMsg))

        ser = serial.Serial(settings.TTY_PORT, '9600', timeout=5)
        time.sleep(2)

        try:
            ser.write(str(incomingMsg))
        except:
            print("Error during serial write")
        
        time.sleep(2)
        try:
            result = ser.read()
        except: