标签:coding world print cep port int connect 127.0.0.1 soc
python 版本 2.7server 端
# -*- coding:utf-8 -*-
import socket
sk = socket.socket()
sk.bind((‘127.0.0.1‘,9999))
sk.listen(5)
while True:
print(‘server waiting...‘)
conn,address = sk.accept()
res = str(conn.recv(1024))
print(res)
conn.sendall(bytes("hello,world!"))
conn.close()
client端
# -*- coding:utf-8 -*-
import socket
sk = socket.socket()
sk.connect((‘127.0.0.1‘,9999))
sk.sendall(bytes(‘你大爷!‘))
ret = str(sk.recv(1024))
print(ret)
sk.close()
标签:coding world print cep port int connect 127.0.0.1 soc
原文地址:http://blog.51cto.com/wuyebamboo/2325156