本文整理汇总了Python中socketserver.ThreadingTCPServer方法的典型用法代码示例。如果您正苦于以下问题:Python socketserver.ThreadingTCPServer方法的具体用法?Python socketserver.ThreadingTCPServer怎么用?Python socketserver.ThreadingTCPServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketserver
的用法示例。
在下文中一共展示了socketserver.ThreadingTCPServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_viewer_server
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def start_viewer_server(port: int, game: Game) -> socketserver.BaseServer:
'''
Start a socket server for the players to connect to
Args:
port: port to connect to viewer on
game: The game information that is being run
use_docker bool: whether to use docker or not
Return:
server_thread: The connection so it can be closed by parent functions at
the appropriate time
'''
# Create handler for mangaing each connections to server
receive_handler = create_receive_handler(game, {}, False, False)
# Start server
server = socketserver.ThreadingTCPServer(('localhost', port), receive_handler)
server_thread = threading.Thread(target=server.serve_forever, daemon=True)
server_thread.start()
return server
示例2: main
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def main():
HOST, PORT = "localhost", 6030
overpass_thread = threading.Thread(target=process_queue_loop)
overpass_thread.daemon = True
overpass_thread.start()
socketserver.ThreadingTCPServer.allow_reuse_address = True
server = socketserver.ThreadingTCPServer((HOST, PORT), RequestHandler)
ip, port = server.server_address
server_thread = threading.Thread(target=server.serve_forever)
server_thread.name = 'server thread'
server_thread.start()
print("Server loop running in thread:", server_thread.name)
server_thread.join()
示例3: run
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def run():
# create a genesis block
t = str(datetime.now())
genesis_block = {
"Index": 0,
"Timestamp": t,
"BPM": 0,
"PrevHash": "",
"Validator": ""
}
genesis_block["Hash"] = calculate_hash(genesis_block)
print(genesis_block)
block_chain.append(genesis_block)
thread_canditate = threading.Thread(target=candidate, args=(candidate_blocks,), daemon=True)
thread_pick = threading.Thread(target=pick_winner, args=(announcements,), daemon=True)
thread_canditate.start()
thread_pick.start()
# start a tcp server
serv = ThreadingTCPServer(('', 9090), HandleConn)
serv.serve_forever()
示例4: main
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def main():
example = 'Example:\n\n$ python3 server.py -U msf -P msf -v -s -l 4444'
args = ArgumentParser(prog='Cooolis-ms',epilog=example)
args.add_argument('-U','--username',help='Metasploit web service username',required=True)
args.add_argument('-P','--password',help='Metasploit web service password',required=True)
args.add_argument('-H','--host',help='Metasploit web service host, Default: localhost',default='localhost')
args.add_argument('-p','--port',help='Metasploit RPC service port, Default: 55553',default=55553,type=int)
args.add_argument('-S','--server',help='Payload sender listen host, Default: localhost',default='localhost')
args.add_argument('-l','--listen',help='Payload listen port, Default: 1111',default=1111,type=int)
args.add_argument('-u','--uri',help='Metasploit RPC service uri, Default: /api/1.0/',default='/api/1.0/')
args.add_argument('-t','--type',help='Payload Type',choices=('exe','ruby','c','dll','vbs','powershell'))
args.add_argument('-s','--ssl',help='Enable ssl, Default: True',action="store_true",default=True)
args.add_argument('-v','--versobe',help='Enable debug',action="store_true")
parser = args.parse_args()
print("[*]Server Host : {host} , Server Port : {port}".format(host=parser.server,port=parser.listen))
server = ThreadingTCPServer((parser.server,parser.listen),Metasploit_RPC.Creator(parser))
server.serve_forever()
示例5: __init__
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def __init__(self, remote_server, ssh_transport, *args, **kwargs):
self.remote_server = remote_server
self.ssh_transport = ssh_transport
socketserver.ThreadingTCPServer.__init__(self, *args, **kwargs)
示例6: setUp
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def setUp(self):
super().setUp()
self.httpd = socketserver.ThreadingTCPServer(("localhost", 0), createHttpHandler(self.repo.name))
self.ip, self.port = self.httpd.server_address
self.server = threading.Thread(target=self.httpd.serve_forever)
self.server.daemon = True
self.server.start()
示例7: serve_listen
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def serve_listen():
server = ThreadingTCPServer((HOST, PORT), Handler)
server.serve_forever()
print(server)
# 主函数
示例8: run
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def run(self):
_ClientHandler.log_info("cht_proxy_daemon start as proxy-server:'{0}';port:'{1}'".format(self._ip_address, self._port_number))
_ClientHandler.log_info("logfile:'{0}'".format(self._logfile))
_serialdevice_initialised=[]
for devicename in self.devicename_keys():
if self.devicename_initflag(devicename) == 0:
#check for already initialised serial device, if not then start transceiver_if
serialdevice = self.transceiver_serialdevice(devicename)
if not serialdevice in (_serialdevice_initialised):
baudrate = self.transceiver_baudrate(devicename)
devicetype = self.transceiver_devicetype(devicename)
#start transceiver-if for that serial device
transceiver_if = cht_transceiver_if(serialdevice, baudrate, devicetype)
#add used serial-device to list
_serialdevice_initialised.append(serialdevice)
#add transceiver to list
self._ht_transceiver_if.append(transceiver_if)
transceiver_if.setDaemon(True)
transceiver_if.start()
#set initialise-flag for devicename
self.devicename_initflag(devicename, 1)
try:
self._server=socketserver.ThreadingTCPServer((self._ip_address, self._port_number), cht_RequestHandler)
self._server.serve_forever()
_ClientHandler.log_critical("cht_proxy_daemon terminated")
_ClientHandler.log_info("---------------------------")
raise
except:
_ClientHandler.log_critical("cht_proxy_daemon terminated")
_ClientHandler.log_info("---------------------------")
raise
示例9: main
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def main():
import argparse
global trace_file, TARGET_HOST, TARGET_PORT
HOST, PORT = "localhost", 8090
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--trace_file', type=argparse.FileType('w'))
parser.add_argument('-b', '--bind', default=HOST)
parser.add_argument('-p', '--port', type=int, default=PORT)
parser.add_argument('-n', '--negotiate', help='Negotiate with the given server name')
parser.add_argument('TARGET_HOST')
parser.add_argument('TARGET_PORT', type=int)
args = parser.parse_args()
TARGET_HOST = args.TARGET_HOST
TARGET_PORT = args.TARGET_PORT
trace_file = args.trace_file
register_types()
NETTCPProxy.negotiate = bool(args.negotiate)
NETTCPProxy.server_name = args.negotiate
if GSSAPIStream is None and NETTCPProxy.negotiate:
log.error("GSSAPI not available, negotiation not possible. Try python2 with gssapi")
sys.exit(1)
server = SocketServer.ThreadingTCPServer((args.bind, args.port), NETTCPProxy)
server.serve_forever()
示例10: test_ThreadingTCPServer
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def test_ThreadingTCPServer(self):
self.run_server(socketserver.ThreadingTCPServer,
socketserver.StreamRequestHandler,
self.stream_examine)
示例11: start
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def start(self):
server = socketserver.ThreadingTCPServer(
(self.host, self.port), _PeerRequestHandler)
server.peer = self
try:
server.serve_forever()
except KeyboardInterrupt as _:
server.server_close()
示例12: main
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def main():
print('Starting')
address = ('localhost', 8080)
server = socketserver.ThreadingTCPServer(address,
MyTCPHandler)
print('Activating server')
server.serve_forever()
示例13: __init__
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def __init__(self, addr, requestHandler=RPCHandler, bind_and_activate=True):
self.instance = None
socketserver.ThreadingTCPServer.__init__(self, addr, requestHandler, bind_and_activate)
self.previous_method = None
self.same_method_call_count = 0
self.process = psutil.Process(os.getpid())
示例14: __init__
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def __init__(self, port=8000):
self._server_address = ("127.0.0.1", port)
self._handler = SimpleHTTPRequestHandlerHere
self.httpd = ThreadingTCPServer(
self._server_address, self._handler, bind_and_activate=False
)
示例15: handle
# 需要导入模块: import socketserver [as 别名]
# 或者: from socketserver import ThreadingTCPServer [as 别名]
def handle(self):
"""重载handle方法"""
print(self.client_address, '连接了服务器')
request_data = self.request.recv(2048).decode('utf-8')
request_header_lines = request_data.splitlines()
# print(request_header_lines[0]) # 第一行为请求头信息
# 解析请求头,获取具体请求信息
pattern = r'[^/]+(/[^ ]*)'
request_html_name = re.match(pattern, request_header_lines[0]).group(1)
# 根据解析到的内容补全将要读取文件的路径
if request_html_name == '/':
request_html_name = STATIC_PATH + 'baidu.html'
else:
request_html_name = STATIC_PATH + request_html_name
# 根据文件情况来返回相应的信息
try:
html_file = open(request_html_name, 'rb')
except FileNotFoundError:
# 文件不存在,则返回文件不存在,并返回状态码404
resp_headers = 'HTTP/1.1 404 not found\r\n'
resp_headers += "Server: PWB" + str(VERSION) + '\r\n'
resp_headers += '\r\n'
resp_body = '==== 404 file not found===='.encode('utf-8')
else:
# 文件存在,则读取文件内容,并返回状态码200
resp_headers = "HTTP/1.1 200 OK\r\n" # 200代表响应成功并找到资源
resp_headers += "Server: PWB" + str(VERSION) + '\r\n' # 告诉浏览器服务器
resp_headers += '\r\n' # 空行隔开body
resp_body = html_file.read() # 显示内容为读取的文件内容
html_file.close()
finally:
resp_data = resp_headers.encode('utf-8') + resp_body # 结合响应头和响应体
# 发送相应数据至浏览器
self.request.send(resp_data)
self.request.close() # HTTP短连接,请求完即关闭TCP连接