实现功能为客户端向服务器端发送数据请求,测试接口状况
主机:
#coding:utf-8 import socket HOST = '127.0.0.1' PORT = 10022 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(10) conn, addr = s.accept() while True: data = conn.recv(1024) print '-------------------' print data if not data: break conn.sendall('ssssssssssss') conn.close()
客户端:
#coding:utf-8 import socket HOST = '127.0.0.1' PORT = 10022 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) print '------------------------' s.sendall('hello socket') data = s.recv(1024) print('Received', repr(data)) s.close()