zoukankan      html  css  js  c++  java
  • python3 socketserver

    -------------------------tcp_server.py-------------------------
    import
    socketserver class Myserver(socketserver.BaseRequestHandler): def handle(self): self.data = self.request.recv(1024).strip() # self.request相当于conn print(self.client_address[0], self.data) self.request.sendall(self.data.upper()) if __name__ == '__main__': ip_port = ("127.0.0.1", 8001) socketserver.TCPServer.allow_reuse_address = True server = socketserver.ThreadingTCPServer(ip_port, Myserver) server.serve_forever()
    -------------------------tcp_client.py-------------------------
    # coding:utf-8 import socket ip_port = ("127.0.0.1", 8001) data = "hello world" with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect(ip_port) sock.sendall(data.encode("utf-8")) from_server_msg = sock.recv(1024).decode("utf-8") print("Send: ", data) print("Received: ", from_server_msg)
  • 相关阅读:
    Tomcat安装与配置
    模板方法模式
    观察者模式
    访问者模式
    策略模式
    迭代器模式
    状态模式
    访问者模式
    备忘录模式
    解释器模式
  • 原文地址:https://www.cnblogs.com/lilyxiaoyy/p/10946916.html
Copyright © 2011-2022 走看看