======server=======:
from socket import *
sock=socket(AF_INET, SOCK_STREAM)
sock.bind(('',12345))
sock.listen(5)
while True:
c, addr=sock.accept()
while True:
try:
data=c.recv(1024)
except:
print(e)
c.close()
break if not data:
break c.send('backinfo'.encode('utf8'))
c.close()
sock.close()
======================
=========Client=============
from socket import *
c=socket(AF_INET, SOCK_STREAM)
c.connect(('127.0.0.1',12345))
c.send('hello from client'.encode('utf8'))
data=c.recv(1024)
if not data:
passprint(data.decode('utf8'))
c.close()
===================================
评论
发表评论