예제 #1
0
def test_basic_connection(is_client):
    if is_client:
        print "Testing basic connection as a client"
        client = RxP.createRxPSocket("localhost", 5000)
        RxP.connectToRxP(client, "localhost", 5001)
        time.sleep(3)
        RxP.closeRxPSocket(client)
    else:
        print "Testing basic connection as a server"
        server = RxP.createRxPSocket("localhost", 5001)
        connection_attempt_address = RxP.listenForRxPConnections(server)
        print("Receieved connection attempt from: ", connection_attempt_address)
        RxP.acceptRxPSocketConnection(server, connection_attempt_address)
        time.sleep(3)
        RxP.closeRxPSocket(server)
예제 #2
0
def test_basic_sending(is_client):
    if is_client:
        print "Testing basic connection as a client"
        client = RxP.createRxPSocket("localhost", 5000)
        RxP.connectToRxP(client, "localhost", 5001)
        RxP.sendData(client, "Hello, World!  This is a big test.   Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test T Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test TTest Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test TesThis is a big test.  Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test")

        RxP.closeRxPSocket(client)
    else:
        print "Testing basic connection as a server"
        server = RxP.createRxPSocket("localhost", 5001)
        connection_attempt_address = RxP.listenForRxPConnections(server)
        print("Receieved connection attempt from: ", connection_attempt_address)
        RxP.acceptRxPSocketConnection(server, connection_attempt_address)

        response = RxP.receiveData(server, 999999)
        print "Received data: ", response
 
        RxP.closeRxPSocket(server)
예제 #3
0
def main():
    # check for number of correct command line arguments
    if len(sys.argv) != 4:
        print ('Please enter arguments in the correct format: X A P' + 
            '\nX: The port number this server should bind to'+
            '\nA: The IP address of NetEmu' + 

            '\nP: The UDP port number of NetEmu ')
        sys.exit()

    # port number at which the FxA-Server's UDP socket should bind to
    try:
        portnumber = int(sys.argv[1])
    except:
        print 'Please enter a valid port number for Server (1025-65536)'
        sys.exit()

    ipaddress = sys.argv[2]

    try:
        emuportnumber = int(sys.argv[3])
    except:
        print 'Please enter a valid port number for NetEmu (1025-65536)'
        sys.exit()

    windowSize = 1

    # check for valid client port numbers
    if portnumber < 1025 or portnumber > 65536: 
        print 'Please enter a valid port number for client (1025-65536)'
        sys.exit()

    # Port number for client must be even
    if portnumber % 2 != 1:
        print 'Port number for server must be odd'
        sys.exit()

    # check for valid IP addresses
    try:
        inet_aton(ipaddress)
    except:
        if ipaddress != "localhost":
            print("Not a valid IP address")
            sys.exit()

    # check for valid NetEmu UDP port number
    if emuportnumber < 1025 or emuportnumber > 65536: 
        print 'Please enter a valid port number for NetEmu (1025-65536)'
        sys.exit()

    global emuportnumber



    # creating and binding rxp socket
    serverSocket = RxP.createRxPSocket(ipaddress, portnumber)
    global serverSocket
    incoming_connection = RxP.listenForRxPConnections(serverSocket)

    # After getting an incoming connection
    RxP.acceptRxPSocketConnection(serverSocket, incoming_connection)
    if RxP.isConnected(serverSocket):
        thread = threading.Thread(target=listenForServerRequests)
        thread.start()
        threads.append(thread)

    #the command loop
    while True:

        # have the user input a command and parse it
        command = raw_input('\nCommand: ').split(" ")
        # check for invalid command
        if len(command) > 2:
            print "Enter a valid command"
            continue

        #check for terminate
        if len(command) == 1:
            # terminate the server
            if command[0] == "terminate":
                terminate()

                for thread in threads:
                    thread.join()
                sys.exit()

                continue
            else:
                print "Please enter a valid command"
                continue
        #check for window
        elif len(command) == 2:
            #window
            if command[0] == "window":
                window(command[1])
                continue
            else:
                print "Please enter a valid command"
                continue