coroutine AbstractEventLoop.create_server(protocol_factory, host=None, port=None, *, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None, reuse_port=None)
Create a TCP server (socket type SOCK_STREAM
) bound to host and port.
Return a Server
object, its sockets
attribute contains created sockets. Use the Server.close()
method to stop the server: close listening sockets.
Parameters:
- The host parameter can be a string, in that case the TCP server is bound to host and port. The host parameter can also be a sequence of strings and in that case the TCP server is bound to all hosts of the sequence. If host is an empty string or
None
, all interfaces are assumed and a list of multiple sockets will be returned (most likely one for IPv4 and another one for IPv6). -
family can be set to either
socket.AF_INET
orAF_INET6
to force the socket to use IPv4 or IPv6. If not set it will be determined from host (defaults tosocket.AF_UNSPEC
). -
flags is a bitmask for
getaddrinfo()
. -
sock can optionally be specified in order to use a preexisting socket object. If specified, host and port should be omitted (must be
None
). -
backlog is the maximum number of queued connections passed to
listen()
(defaults to 100). -
ssl can be set to an
SSLContext
to enable SSL over the accepted connections. - reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on UNIX.
- reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows.
This method is a coroutine.
Changed in version 3.5: On Windows with ProactorEventLoop
, SSL/TLS is now supported.
See also
The function start_server()
creates a (StreamReader
, StreamWriter
) pair and calls back a function with this pair.
Changed in version 3.5.1: The host parameter can now be a sequence of strings.
Please login to continue.