本文整理汇总了Python中socketserver.TCPServer类的典型用法代码示例。如果您正苦于以下问题:Python TCPServer类的具体用法?Python TCPServer怎么用?Python TCPServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TCPServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
host = ''
port = 7777
server = None
board = PyMata3(5)
shoulder = Actuator(board, 9)
arm = Actuator(board, 10)
elbow = Actuator(board, 11, min_angle=-90, max_angle=90, offset=-90)
global mech_arm
mech_arm = MechanicalArm(
[shoulder, arm, elbow],
Fabrik(
joint_positions=[Vector2(0, 0), Vector2(53, 0), Vector2(100, 0)],
link_lengths=[53, 47],
tolerance=0.1
)
)
sleep(2)
while server is None:
try:
server = TCPServer((host, port), ConnectionHandler)
except OSError:
port += 1
continue
print("Serving on: {}".format(port))
server.serve_forever()
server.server_close()
开发者ID:saleone,项目名称:bachelor-thesis,代码行数:30,代码来源:server.py
示例2: server
class server(object):
def __init__(self, offtime):
self.offtime = offtime
self.server = TCPServer(
('127.0.0.1', 7654),
BaseRequestHandler
)
self.server_thread = None
self.server.running = False
def shutdown(self, signum, frame):
print("[*] Shutting down server thread")
self.server.running = False
self.server.shutdown()
def up(self):
signal.signal(signal.SIGTERM, self.shutdown)
signal.signal(signal.SIGINT, self.shutdown)
signal.signal(signal.SIGALRM, self.shutdown)
signal.alarm(self.offtime)
self.server_thread = threading.Thread(target=self.server.serve_forever)
print("[*] Starting server thread")
self.server_thread.start()
self.server.running = True
print("[*] Waiting for server thread to shut down")
while self.server.running:
time.sleep(1)
self.server_thread.join()
print("[*] Server thread terminated")
开发者ID:rpurizaca,项目名称:python-programming,代码行数:35,代码来源:signal-server_off.py
示例3: __init__
class PickleServer:
def __init__(self, address):
''' @param address: A tuple of ip and port.
For example, PickleServer(('127.0.0.1', 3750))
'''
handler = self.handle
from socketserver import StreamRequestHandler
class Handler(StreamRequestHandler):
def handle(self):
from pclib import iostream
stream = iostream(self.rfile, self.wfile)
stream = PickleStream(stream)
handler(stream)
from socketserver import TCPServer
self.server = TCPServer(address, Handler)
def start(self):
from threading import Thread
Thread(target = self.run).start()
def run(self):
self.server.serve_forever()
def shutdown(self):
self.server.shutdown()
def handle(self, stream):
pass
开发者ID:caipeichao,项目名称:Histo,代码行数:28,代码来源:picklestream.py
示例4: run_server
def run_server(port, site_dir, ctx):
output_dir = ctx["OutputDir"]
# start server
class RequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if hasattr(self, "error") and self.error is not None:
self.send_response(200, 'OK')
self.send_header('Content-type', 'html')
self.end_headers()
self.wfile.write(bytes(self.error, 'UTF-8'))
else:
super().do_GET()
def translate_path(self, path):
return os.path.join(site_dir, output_dir, path[1:])
handler = RequestHandler
httpd = TCPServer(("", port), handler)
atexit_register(lambda: httpd.shutdown())
# start update thread
thread = Thread(target=update, args=(site_dir, ctx, handler, port))
thread.daemon = True
thread.start()
print("Serving at http://localhost:" + str(port) + "/")
httpd.serve_forever()
开发者ID:qema,项目名称:nanosite,代码行数:26,代码来源:server.py
示例5: main
def main():
sys.excepthook = Pyro4.util.excepthook
print("Welcome to the prototype !\n")
print("Would you like to be [s]erver or [c]lient? (s/c)")
user_interaction = input(":> ").strip()
if "s" == user_interaction:
print("Please enter the IP-Address which the server should listen on.")
ip_adr = input(":> ").strip()
rl_ip_adr = Pyro4.socketutil.getInterfaceAddress(ip_adr)
print("\nIMPORTANT: The Server will listen on: %s" % rl_ip_adr)
HOST, PORT = rl_ip_adr, 20111
daemon = Pyro4.Daemon(host=rl_ip_adr)
srv_uri = daemon.register(Server())
tcpserver = TCPServer((HOST, PORT),
lambda *args, **keys: SingleTCPHandler(send_server_uri, srv_uri.asString(), *args,
**keys))
t = threading.Thread(target=tcpserver.serve_forever)
t.start()
print("Serving...")
daemon.requestLoop()
tcpserver.shutdown()
elif "c" == user_interaction:
print("Please enter your name.")
name = input(":> ").strip()
print("Please enter the ip of the server.")
srv_ip = input(":> ").strip()
client = Client(name, srv_ip)
clt_uri = client.get_uri().asString()
TCPSender.send(clt_uri, (srv_ip, 20111))
client.start()
while client.is_running():
time.sleep(1)
contact = Contact(name, client.get_srv_uri())
contact.register()
input("Press Enter to exit.")
contact.deregister()
开发者ID:wi13b071,项目名称:osd_repo,代码行数:59,代码来源:main.py
示例6: runserver
def runserver(config=None):
if config is None:
config={'host':'','port':200}
serv=TCPServer((config['host'],config['port']),MyHandler)
print('listening port: '+str(config['port']))
print('server name : svncount')
print('server type : tcp')
serv.serve_forever()
开发者ID:freshman88,项目名称:python,代码行数:8,代码来源:svncount_server.py
示例7: __init__
class MobileServer:
def __init__(self, address):
''' @param address: A tuple of ip and port. '''
from socketserver import TCPServer
self.server = TCPServer(address, MobileHandler)
def run(self):
self.server.serve_forever()
开发者ID:caipeichao,项目名称:Histo,代码行数:8,代码来源:mobileserver.py
示例8: iiif_server
def iiif_server():
address = ('localhost', 0)
httpd = TCPServer(address, SimpleHTTPRequestHandler)
t = threading.Thread(target=httpd.serve_forever)
t.start()
yield httpd.server_address
httpd.shutdown()
t.join()
开发者ID:MITLibraries,项目名称:tryiiif,代码行数:8,代码来源:conftest.py
示例9: start
def start(self):
TCPServer.__init__(self, ('localhost', int(HTTP_PORT)), CustomHandler)
self.RESOURCE_LOCATION = path.abspath(path.dirname(__file__))
print("Server serving from DocumentRoot:" + self.RESOURCE_LOCATION)
chdir(self.RESOURCE_LOCATION)
server_thread = threading.Thread(name='test_file_server', target=self.serve_forever)
server_thread.daemon = True
server_thread.start()
开发者ID:robotframework,项目名称:remoteswinglibrary,代码行数:8,代码来源:FileServer.py
示例10: run
def run(self):
"""
Main thread method. Open socket and waiting for connections.
"""
server = TCPServer((self.host, self.port), TCPHandler)
server.lymphocytes_getter = self.lymphocytes_getter
# runs forever - so make this thread daemon
server.serve_forever()
开发者ID:ebnuakoh1,项目名称:ArtificialImmuneSystem,代码行数:9,代码来源:exchanger.py
示例11: start_server_for_ips
def start_server_for_ips():
serv = TCPServer(('', 20007), EchoHandler)
ser = Thread(target=serv.serve_forever)
ser.start()
global members_count
members_count = 2
while members_count:
sleep(1)
serv.shutdown()
开发者ID:kobso1245,项目名称:Don-t-get-angry,代码行数:9,代码来源:backbone_server.py
示例12: serve_forever
def serve_forever(self, poll_interval=0.5):
"""Handle one request at a time until shutdown.
Polls for shutdown every poll_interval seconds. Ignores
self.timeout. If you need to do periodic tasks, do them in
another thread.
"""
self._serving_event.set()
self._shutdown_request_event.clear()
TCPServer.serve_forever(self, poll_interval=poll_interval)
开发者ID:usk-group,项目名称:coilmq,代码行数:10,代码来源:socket_server.py
示例13: server_close
def server_close(self):
"""
Closes the socket server and any associated resources.
"""
self.log.debug("Closing the socket server connection.")
TCPServer.server_close(self)
self.queue_manager.close()
self.topic_manager.close()
if hasattr(self.authenticator, 'close'):
self.authenticator.close()
self.shutdown()
开发者ID:usk-group,项目名称:coilmq,代码行数:11,代码来源:socket_server.py
示例14: serve
def serve(self):
self.monitor()
os.chdir(self.directory)
request_handler = server.SimpleHTTPRequestHandler
httpd = TCPServer(('', self.port), request_handler)
try:
print('Preview available at http://0.0.0.0:{}/'.format(self.port))
httpd.serve_forever()
except KeyboardInterrupt:
httpd.shutdown()
开发者ID:cknv,项目名称:beetle-preview,代码行数:12,代码来源:__init__.py
示例15: SimpleServer
class SimpleServer(Thread):
def __init__(self):
Thread.__init__(self)
self.httpd = None
def run(self):
chdir(root + "/_site")
self.httpd = TCPServer(('', 8000), SimpleHTTPRequestHandler)
self.httpd.serve_forever()
def shutdown(self):
self.httpd.shutdown()
开发者ID:dkuntz2,项目名称:fjord-tasks,代码行数:12,代码来源:server.py
示例16: __init__
def __init__(self,
server_address, # Server address (host,port)
RequestHandlerClass,
certfile, # Certificate path
keyfile, # Key path
ssl_version=ssl.PROTOCOL_SSLv23, #Comunicatio+n protocol
ciphers="DEFAULT",
bind_and_activate=True):
TCPServer.__init__(self, server_address, RequestHandlerClass, bind_and_activate)
self.certfile = certfile
self.keyfile = keyfile
self.ssl_version = ssl_version
self.ciphers=ciphers
开发者ID:hielfx,项目名称:SSII_Proyecto_3,代码行数:13,代码来源:ssl_server_socket.py
示例17: __init__
def __init__(self, server_address, RequestHandlerClass, certfile, keyfile, bind_and_activate=True):
TCPServer.__init__(self,
server_address,
RequestHandlerClass)
self.socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
server_side=True,
certfile=certfile,
keyfile=keyfile,
do_handshake_on_connect=False)
if bind_and_activate:
self.server_bind()
self.server_activate()
开发者ID:OnyxChills,项目名称:OnyxManager,代码行数:14,代码来源:Master.py
示例18: server_bind
def server_bind(self):
"""
Override server_bind to store the server name, even in IronPython.
See https://ironpython.codeplex.com/workitem/29477
"""
TCPServer.server_bind(self)
host, port = self.socket.getsockname()[:2]
self.server_port = port
try:
self.server_name = socket.getfqdn(host)
except ValueError:
# Use the local host name in case of error, like CPython does
self.server_name = socket.gethostname()
开发者ID:tcalmant,项目名称:ipopo,代码行数:14,代码来源:basic.py
示例19: serve
def serve(self):
cwd = os.getcwd()
os.chdir(self.directory)
httpd = TCPServer(("", self.port), SimpleHTTPRequestHandler)
try:
self.logger.log(
"server running on http://localhost:{0}".format(self.port)
)
httpd.serve_forever()
except KeyboardInterrupt:
self.logger.log("shutting down server\n")
os.chdir(cwd)
开发者ID:fallenhitokiri,项目名称:drupan,代码行数:15,代码来源:serve.py
示例20: main
def main():
ap = argparse.ArgumentParser()
ap.add_argument('port', nargs='?', type=int, default='8000')
args = ap.parse_args()
port = args.port
try:
httpd = TCPServer(("", port), Handler)
url = 'http://127.0.0.1:{}/crowdmap'.format(port)
print ("Open this url in your browser: {}".format(url))
webbrowser.open_new(url)
httpd.serve_forever()
except KeyboardInterrupt:
print ('port {} closed'.format(port))
开发者ID:yenatch,项目名称:crowdmap,代码行数:15,代码来源:server.py
注:本文中的socketserver.TCPServer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论