# pcj import socket def main(): tcp_server_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) tcp_server_socket.bind(("",9990)) tcp_server_socket.listen(128) while True: print("等侍一个客户的连接") new_client_socket,listen_addr=tcp_server_socket.accept() print("一个新客户已经连接",listen_addr) while True: recv_date=new_client_socket.recv(1024) if recv_date: #如recv_date 有数据,就接收,还服务 else break print("客户请求的是",recv_date.decode("GBK")) else: break new_client_socket.send("hello----OK----".encode("gbk")) new_client_socket.close() tcp_server_socket.colse() if __name__ == '__main__': main()