操作系统的版本为centos7.5
使用系统自带的python版本
编写duankou.py
import socket ip_port = ('192.168.122.136',9999) sk = socket.socket() sk.bind(ip_port) sk.listen(5) while True: print ('server waiting...') conn,addr = sk.accept() client_data = conn.recv(1024) print (str(client_data,'utf8')) conn.sendall(bytes('abc','utf8')) conn.close()
直接运行
python duankou.py
netstat -tnlp|grep 9999