예제 #1
0
def test_4():
    client = RxP.createRxPSocket("localhost", 5000)
    server = RxP.createRxPSocket("localhost", 5001)
    RxP.listenForRxPConnections(server)
    RxP.connectToRxP(client, "localhost", 5001)
    RxP.sendData(client, "Hello")
    RxP.close(client)
예제 #2
0
def main():

    rxpProtocol = None

    # Handling the argument
    arg = sys.argv
    if len(arg) < 3 or len(arg) > 4:
        print 'Invalid command. Please try again.'
        sys.exit()

    # pass the command line arguments
    try:
        clientPort = int(arg[1])
    except ValueError:
        print 'Invalid command. Please try again.'
        sys.exit()
    # validate
    if not 0 < clientPort < 65536:
        print 'Invalid port number. Please try again.'
        sys.exit()

    # Server IP address
    serverIP = arg[2]

    if not _validIP(serverIP):
        print 'IP address is not valid, please try again'
        sys.exit()

    # netEmu port number
    try:
        netEmuPort = int(arg[3])
    except ValueError:
        print 'Invalid command. Please try again.'
        sys.exit()
    # validate
    if not 0 < netEmuPort < 65536:
        print 'Invalid port number. Please try again.'
        sys.exit()

    # Dest. port number
    desPort = clientPort + 1

    log = "output-client.txt"

    clientProtocol = None
    sendThread = None

    connThread = None
    sThread = None

    #execute user's commend
    while True:
        time.sleep(.500)
        Sinput = raw_input("type connect - to establish connection \n"
                    + "get 'filename' - to download the file from server \n"
                    + "post 'filename' - to upload the file to server \n"
                    + "Window W - to change the window size \n"
                    + "disconnect - to close the connection\n"
                    + 'quit - to quit the application\n')
        if Sinput.__eq__("connect"):
            rxpProtocol = RxP(serverIP, netEmuPort, clientPort, desPort, log)
            clientProtocol = RecvThread(rxpProtocol)
            clientProtocol.start()
            rxpProtocol.connect()
        # get file form server
        elif "get" in Sinput:
            if rxpProtocol != None:
                s = Sinput.split()
                rxpProtocol.getFile(s[1])
        # post file form server
        elif "post" in Sinput:
            if rxpProtocol != None:
                s = Sinput.split()
                sendThread = SendThread(rxpProtocol, s[1])
                sendThread.start()
        # set the window size
        elif "window" in Sinput:
            if rxpProtocol != None:
                s = Sinput.split()
                try:
                    window = int(s[1])
                except ValueError:
                    print 'Invalid window size. Please try again.'
                    sys.exit()
                if not 0 < window < 50:
                    print 'Window size too big. Please try again.'
                    sys.exit()
                print "Set window size to " + str(window)
                rxpProtocol.setWindowSize(window)
        #close connection
        elif Sinput.__eq__("disconnect"):
            if rxpProtocol != None:
                rxpProtocol.close()
                clientProtocol.stop()
                rxpProtocol.socket.close()
                rxpProtocol = None
        elif Sinput.__eq__("quit"):
            if rxpProtocol:
                print 'disconnect before quit'
            else:
                break
예제 #3
0
def main():

    print ("Server Starts")

    # Handling the argument
    arg = sys.argv
    if len(arg) < 3 or len(arg) > 4:
        print 'Invalid command. Please try again.'
        sys.exit()

    log = "output-server.txt"

    #pass the command line arguments
    try:
        hostPort = int(arg[1])
    except ValueError:
        print 'Invalid command. Please try again.'
        sys.exit()
    # validate
    if not 0 < hostPort < 65536:
        print 'Invalid port number. Please try again.'
        sys.exit()

    #Server IP address
    serverIP = arg[2]
    # validate
    if not _validIP(serverIP):
        print 'IP address is not valid, please try again'
        sys.exit()

    # netEmu port number
    try:
        netEmuPort = int(arg[3])
    except ValueError:
        print 'Invalid command. Please try again.'
        sys.exit()
    # validate
    if not 0 < netEmuPort < 65536:
        print 'Invalid port number. Please try again.'
        sys.exit()

    # Dest. port number
    desPort = hostPort - 1

    rxpProtocol = RxP(serverIP, netEmuPort, hostPort, desPort, log)
    serverProtocol = RecvThread(rxpProtocol)
    serverProtocol.start()

    # execute user's commend
    while (True):
        Sinput = raw_input("type Window W - to change the window size \n"
                    + "terminate - to terminate the server\n")
        if "window" in Sinput:
            s = Sinput.split()
            try:
                wsize = int(s[1])
            except ValueError:
                print 'Invalid window size. Please try again.'
                sys.exit()
            if not 0 < wsize < 50:
                print 'Window size too big. Please try again.'
                sys.exit()
            print "Set window size to " + str(wsize)
            rxpProtocol.setWindowSize(wsize)
        # close server
        elif Sinput.__eq__("terminate"):
            rxpProtocol.close()
            serverProtocol.stop()
            for thread in rxpProtocol.threads:
                thread.stop()
            print ("Server is closed")
            break