server python and file opening error

I am starting in python and developing a client / server script with some input parameters in terminal,arguments:(in) (out) (ip) (port) (mode) according to the code below.In passive mode, it functions as a server, in active mode it functions as a client. But I do not understand the reason for the errors presented. Can someone explain to me what's going on? Thanks.

code

def Main():

    mode = sys.argv[5]

    i = 0  # Auxiliar variable in loop

    if (mode == "passive"):
        port = int(sys.argv[4])
        mySocket = socket.socket()
        mySocket.bind(('', port))  # Passive connection, for server
        mySocket.listen(1)
        conn, addr = mySocket.accept()
        conn.settimeout(1)  # Timeout = 1 segundo
        conn.setblocking(0)  # Non blockable mode
        print("Connection from: " + str(addr))
        print("Connected as server")
        in_arq = open(sys.argv[1], 'r')
        message = in_arq.read()  # File to be send
        out_arq = open(sys.argv[2], 'w')  # File to save data received


    elif (mode == "ative"):
        host = sys.argv[3]
        port = int(sys.argv[4])
        mySocket = socket.socket()
        mySocket.connect((host, port))  # Active connection, for client
        mySocket.settimeout(1)  # Timeout = 1 segundo
        mySocket.setblocking(0)  # Non blockable mode
        print("Connected as client")
        in_arq = open(sys.argv[1], 'r')
        message = in_arq.read()  # File to be send
        out_arq = open(sys.argv[2], 'w')  # File to save data received

    else:
        print("Wrong arguments.")

if __name__ == '__main__':
    Main()

errors:

C:UsersAppDataLocalProgramsPythonPython35-32python.exe C:/Users/Desktop/emulator.py C:UsersDesktoptextinput C:UsersDesktoptextoutput 127.0.0.1 54000 ative

Traceback (most recent call last):

File "C:/Users/Desktop/emulator.py", line 221, in <module>
Main()

File "C:/Users/Desktop/emulator.py", line 202, in Main
in_arq = open(sys.argv[1], 'r')

FileNotFoundError: [Errno 2] No such file or directory: 'C:UsersDesktoptextinput'

Connected as client

链接地址: http://www.djcxy.com/p/9306.html

上一篇: 为什么使用def main()?

下一篇: 服务器python和文件打开错误