我的主机上的套接字编程问题

时间:2019-02-11 15:11:42

标签: python sockets websocket web-project

我想使用一个网站向客户端应用程序发送一些命令,但是在我的主机中,我只能访问端口80和443,是否可以使用这些端口进行套接字编程?

我已经在某些端口(例如8889)上尝试过我的代码,但是这些在我的主机上不可用

    def send_to_client(key)://///the function on website that sends data to client
        HOST = '10.42.0.158'  # The server's hostname or IP address
        PORT = 8889       # The port used by the server
        connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        connection.connect((HOST, PORT))
        print("problem with socket")
        # old = termios.tcgetattr(sys.stdin)
        tty.setcbreak(sys.stdin.fileno())
        try:    
            /////if key is ok send it to client app
                connection.sendall(key)
                return key + " sent succesfully"
            else:
                return "not proper input"
                            # key = sys.stdin.read(1)
        finally:
            termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old)    

    def recv_data()://///the function on client app that receive data from website
        global data
        #now keep talking with the client
        while 1:
            #wait to accept a connection - blocking call
            conn, addr = s.accept()
            print ('Connected with ' + addr[0] + ':' + str(addr[1]))
            while True:

                d = conn.recv(1024).strip().decode('utf-8')
                data = d
                break

我想知道是否可以使用端口80进行此套接字编程应用程序

0 个答案:

没有答案