使用python socket实现双向的tcp通信
很久之前玩过的python socket,今天用来做个双向的通信程序。 服务端代码: server.py # coding: utf-8 # tcp stream server import socket import logging import time import datetime as dt from threading import Thread, currentThread # 配置logging logging.basicConfig( level=logging.INFO, format="%(asctime)s%(levelname)s%(process)s%(threadName)s|%(message)s", ) class Server: """ socket 服务端 """ def __init__(self, host='localhost', port=8099): self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock.bind((host, port)) self.msg = None def read(self, conn: socket.socket = None): """ 从tcp连接里面读取数据 """ while True: try: data = conn....