socket

客户端:

import socket

sk=socket.socket()
address = ('127.0.0.1',8000)
sk.connect(address)


while True:
inp = input('>>>')
sk.sendall(bytes(inp,'utf-8'))
if inp=='exit':
break

data = sk.recv(1024)
data = str(data,'utf-8')
print(data)
sk.close()

服务器:
# !usr/bin/python3
#-*- utf-8 -*-
# Author:huang
# @time

import socket
sk=socket.socket()
address = ('127.0.0.1',8000)
sk.bind(address)
sk.listen(4)
conn,dir=sk.accept()
while True:

data = conn.recv(1024)
data = str(data,'utf-8')
print(data)
inp = input('>>>')
conn.sendall(bytes(inp,'utf-8'))

conn.close()




posted @ 2018-03-18 17:31  飘零0  阅读(111)  评论(0编辑  收藏  举报