标签:nbsp nec style 地球 blog dal client 运行 color
一、简单服务端及客户端示例
1.1.简单socket server端示例
#!/usr/bin/env python #-*- coding:utf-8 -*- import socket ip_port = (‘127.0.0.1‘,9999) sk = socket.socket() sk.bind(ip_port) sk.listen() while True: print("server waiting......") Conn,Addr = sk.accept() ClientData = self.request.recv(1024) print(str(ClientData,‘utf8‘)) self.request.sendall(bytes("不要回答,不要回答,不要回答","utf8")) Conn.close()
1.2.简单socket client端示例
#!/usr/bin/env python #-*- coding:utf-8 -*- import socket ip_port = (‘127.0.0.1‘,9999) sk = socket.socket() sk.connect(ip_port) sk.sendall(bytes("请求占领地球",‘utf8‘)) ServerReplay = sk.recv(1024) print(str(ServerReplay,‘utf8‘)) sk.close()
运行服务端:
运行客户端:
标签:nbsp nec style 地球 blog dal client 运行 color
原文地址:http://www.cnblogs.com/ckl893/p/7026398.html