#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import threading
bind_ip = "127.0.0.1"
bind_port = 9999
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind((bind_ip,bind_port))
server.listen(50)
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("收到了,小乖乖!")
client_socket.close()
while True:
client,addr = server.accept()
print("[*]收到连接,地址:%s:%d"%(addr[0],addr[1]))
client_handler = threading.Thread(target=handle_client,arg_str=(client,))
client_handler.start()
Comments
Post a Comment