唯一目的:短平快!
语言:Python
模块:socket,threading
#coding=utf-8
import socket
import threading
bind_ip="0.0.0.0"
bind_port=9999
server=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #创建对象
server.bind((bind_ip,bind_port)) #绑定地址
server.listen(5) #启动监听,最大连接为5
print"[*] listening on %s:%d" % (bind_ip,bind_port)
def handle_client(client_socket):
request=client_socket.recv(1024)
print "[*] received:%s" % request #接收客户端的数据
client_socket.send("ACK!\n hello client! \n I am server!") #返回响应
client_socket.close()
while True:
client,addr=server.accept() #client保存套接字对象
print "[*] acceptted connected from:%s:%d" % (addr[0],addr[1]) #addr保存连接细节
client1=threading.Thread(target=handle_client,args=(client,)) #创建和启动线程
client1.start()