标签:obj imp dump hello import style class connect not
server
import socket host="localhost" port=10000 s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.bind((host,port)) s.listen(5) while(1): sock,addr=s.accept() print("got connection form ",sock.getpeername()) sock.send(‘Hello!‘) data=sock.recv(1024) if not data: print("no client") else: print("cdcd",data) data=sock.recv(1024) if not data: print("no client") else: print(data) data=sock.recv(1024) if not data: print("no client") else: print(data)
输出:
(‘got connection form ‘, (‘127.0.0.1‘, 50773)) (‘cdcd‘, ‘{"req": "get", "obj": "uuid", "param": {}, "seq": 0}‘) no client no client
client
# -*- coding: utf-8 -*- """ Created on Mon Mar 28 22:40:41 2016 @author: zhanghc """ import socket import json import time host="localhost" port=10000 s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect((host,port)) data={"req":"get","obj":"uuid","seq":0,"param":{}} j = json.dumps(data) s.send(j) print(s.recv(1024)) s.close()
输出
Hello!
标签:obj imp dump hello import style class connect not
原文地址:https://www.cnblogs.com/sea-stream/p/10313975.html