AntanoTCPServer¶
-
class
services.
AntanoTCPServer
(*args, **kwargs)¶ Bases:
tornado.tcpserver.TCPServer
A sub-classed tornado tcp server
Parameters: {TCPServer tornado} -- enhanced tornado tcp server (TCPServer) – Methods Summary
add_socket
(socket)Singular version of add_sockets. add_sockets
(sockets)Makes this server start accepting connections on the given sockets. bind
(port, address, family, backlog, reuse_port)Binds this server to the given port on the given address. handle_stream
(stream, address)Async handle_stream for getting message real async listen
(port, address)Starts accepting connections on the given port. send_message
(message, stream)Async send message for tcp stream start
(num_processes, NoneType] = 1, max_restarts)Starts this server in the .IOLoop. stop
()Stops listening for new connections. Methods Documentation
-
add_socket
(socket: socket.socket) → None¶ Singular version of add_sockets. Takes a single socket object.
-
add_sockets
(sockets: Iterable[socket.socket]) → None¶ Makes this server start accepting connections on the given sockets.
The
sockets
parameter is a list of socket objects such as those returned by ~tornado.netutil.bind_sockets. add_sockets is typically used in combination with that method and tornado.process.fork_processes to provide greater control over the initialization of a multi-process server.
-
bind
(port: int, address: str = None, family: socket.AddressFamily = <AddressFamily.AF_UNSPEC: 0>, backlog: int = 128, reuse_port: bool = False) → None¶ Binds this server to the given port on the given address.
To start the server, call start. If you want to run this server in a single process, you can call listen as a shortcut to the sequence of bind and start calls.
Address may be either an IP address or hostname. If it’s a hostname, the server will listen on all IP addresses associated with the name. Address may be an empty string or None to listen on all available interfaces. Family may be set to either socket.AF_INET or socket.AF_INET6 to restrict to IPv4 or IPv6 addresses, otherwise both will be used if available.
The
backlog
argument has the same meaning as for socket.listen <socket.socket.listen>. Thereuse_port
argument has the same meaning as for .bind_sockets.This method may be called multiple times prior to start to listen on multiple ports or interfaces.
Changed in version 4.4: Added the
reuse_port
argument.
-
handle_stream
(stream, address)¶ Async handle_stream for getting message real async
Parameters: - {IOStream} -- current client stream (stream) –
- {Address} -- current ip and port from client (address) –
-
listen
(port: int, address: str = '') → None¶ Starts accepting connections on the given port.
This method may be called more than once to listen on multiple ports. listen takes effect immediately; it is not necessary to call TCPServer.start afterwards. It is, however, necessary to start the .IOLoop.
-
send_message
(message, stream)¶ Async send message for tcp stream
Parameters: - {bytes} -- Current message to send (message) –
- {IOStream} -- Current client stream (stream) –
-
start
(num_processes: Union[int, NoneType] = 1, max_restarts: int = None) → None¶ Starts this server in the .IOLoop.
By default, we run the server in this process and do not fork any additional child process.
If num_processes is
None
or <= 0, we detect the number of cores available on this machine and fork that number of child processes. If num_processes is given and > 1, we fork that specific number of sub-processes.Since we use processes and not threads, there is no shared memory between any server code.
Note that multiple processes are not compatible with the autoreload module (or the
autoreload=True
option to tornado.web.Application which defaults to True whendebug=True
). When using multiple processes, no IOLoops can be created or referenced until after the call toTCPServer.start(n)
.The
max_restarts
argument is passed to .fork_processes.Changed in version 6.0: Added
max_restarts
argument.
-
stop
() → None¶ Stops listening for new connections.
Requests currently in progress may still continue after the server is stopped.
-