class_docstr: A non-blocking, single-threaded TCP server.
  
  To use `TCPServer`, define a subclass which overrides the `handle_stream`
  method. For example, a simple echo server could be defined like this::
  
    from tornado.tcpserver import TCPServer
    from tornado.iostream import StreamClosedError
  
    class EchoServer(TCPServer):
        async def handle_stream(self, stream, address):
            while True:
                try:
                    data = await stream.read_until(b"\n") await
                    stream.write(data)
                except StreamClosedError:
                    break
  
  To make this server serve SSL traffic, send the ``ssl_options`` keyword
  argument with an `ssl.SSLContext` object. For compatibility with older
  versions of Python ``ssl_options`` may also be a dictionary of keyword
  arguments for the `ssl.SSLContext.wrap_socket` method.::
  
     ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
     ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),
                             os.path.join(data_dir, "mydomain.key"))
     TCPServer(ssl_options=ssl_ctx)
  
  `TCPServer` initialization follows one of three patterns:
  
  1. `listen`: single-process::
  
          async def main():
              server = TCPServer()
              server.listen(8888)
              await asyncio.Event.wait()
  
          asyncio.run(main())
  
     While this example does not create multiple processes on its own, when
     the ``reuse_port=True`` argument is passed to ``listen()`` you can run
     the program multiple times to create a multi-process service.
  
  2. `add_sockets`: multi-process::
  
          sockets = bind_sockets(8888)
          tornado.process.fork_processes(0)
          async def post_fork_main():
              server = TCPServer()
              server.add_sockets(sockets)
              await asyncio.Event().wait()
          asyncio.run(post_fork_main())
  
     The `add_sockets` interface is more complicated, but it can be used with
     `tornado.process.fork_processes` to run a multi-process service with all
     worker processes forked from a single parent.  `add_sockets` can also be
     used in single-process servers if you want to create your listening
     sockets in some way other than `~tornado.netutil.bind_sockets`.
  
     Note that when using this pattern, nothing that touches the event loop
     can be run before ``fork_processes``.
  
  3. `bind`/`start`: simple **deprecated** multi-process::
  
          server = TCPServer()
          server.bind(8888)
          server.start(0)  # Forks multiple sub-processes
          IOLoop.current().start()
  
     This pattern is deprecated because it requires interfaces in the
     `asyncio` module that have been deprecated since Python 3.10. Support for
     creating multiple processes in the ``start`` method will be removed in a
     future version of Tornado.
  
  .. versionadded:: 3.1
     The ``max_buffer_size`` argument.
  
  .. versionchanged:: 5.0
     The ``io_loop`` argument has been removed.
class_docstr_tok: ["A","non-blocking",",","single-threaded","TCP","server",".","To","use","`","TCPServer","`",",","define","a","subclass","which","overrides","the","`","handle_stream","`","method",".","For","example",",","a","simple","echo","server","could","be","defined","like","this",":",":","from","tornado.tcpserver","import","TCPServer","from","tornado.iostream","import","StreamClosedError","class","EchoServer","(","TCPServer",")",":","async","def","handle_stream","(","self",",","stream",",","address",")",":","while","True",":","try",":","data","=","await","stream.read_until","(","b","''","\\n","''",")","await","stream.write","(","data",")","except","StreamClosedError",":","break","To","make","this","server","serve","SSL","traffic",",","send","the","``","ssl_options","``","keyword","argument","with","an","`","ssl.SSLContext","`","object",".","For","compatibility","with","older","versions","of","Python","``","ssl_options","``","may","also","be","a","dictionary","of","keyword","arguments","for","the","`","ssl.SSLContext.wrap_socket","`","method",".",":",":","ssl_ctx","=","ssl.create_default_context","(","ssl.Purpose.CLIENT_AUTH",")","ssl_ctx.load_cert_chain","(","os.path.join","(","data_dir",",","``","mydomain.crt","''",")",",","os.path.join","(","data_dir",",","``","mydomain.key","''",")",")","TCPServer","(","ssl_options=ssl_ctx",")","`","TCPServer","`","initialization","follows","one","of","three","patterns",":","1",".","`","listen","`",":","single-process",":",":","async","def","main","(",")",":","server","=","TCPServer","(",")","server.listen","(","8888",")","await","asyncio.Event.wait","(",")","asyncio.run","(","main","(",")",")","While","this","example","does","not","create","multiple","processes","on","its","own",",","when","the","``","reuse_port=True","``","argument","is","passed","to","``","listen","(",")","``","you","can","run","the","program","multiple","times","to","create","a","multi-process","service",".","2",".","`","add_sockets","`",":","multi-process",":",":","sockets","=","bind_sockets","(","8888",")","tornado.process.fork_processes","(","0",")","async","def","post_fork_main","(",")",":","server","=","TCPServer","(",")","server.add_sockets","(","sockets",")","await","asyncio.Event","(",")",".wait","(",")","asyncio.run","(","post_fork_main","(",")",")","The","`","add_sockets","`","interface","is","more","complicated",",","but","it","can","be","used","with","`","tornado.process.fork_processes","`","to","run","a","multi-process","service","with","all","worker","processes","forked","from","a","single","parent",".","`","add_sockets","`","can","also","be","used","in","single-process","servers","if","you","want","to","create","your","listening","sockets","in","some","way","other","than","`","~tornado.netutil.bind_sockets","`",".","Note","that","when","using","this","pattern",",","nothing","that","touches","the","event","loop","can","be","run","before","``","fork_processes","``",".","3",".","`","bind","`","\/","`","start","`",":","simple","*","*","deprecated","*","*","multi-process",":",":","server","=","TCPServer","(",")","server.bind","(","8888",")","server.start","(","0",")","#","Forks","multiple","sub-processes","IOLoop.current","(",")",".start","(",")","This","pattern","is","deprecated","because","it","requires","interfaces","in","the","`","asyncio","`","module","that","have","been","deprecated","since","Python","3.10",".","Support","for","creating","multiple","processes","in","the","``","start","``","method","will","be","removed","in","a","future","version","of","Tornado",".","..","versionadded",":",":","3.1","The","``","max_buffer_size","``","argument",".","..","versionchanged",":",":","5.0","The","``","io_loop","``","argument","has","been","removed","."]
docstr: 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>`. The ``reuse_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.
  
  .. versionchanged:: 4.4
     Added the ``reuse_port`` argument.
  
  .. versionchanged:: 6.2
     Added the ``flags`` argument to match `.bind_sockets`.
  
  .. deprecated:: 6.2
     Use either ``listen()`` or ``add_sockets()`` instead of ``bind()``
     and ``start()``.
docstr_tok: ["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",">","`",".","The","``","reuse_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",".","..","versionchanged",":",":","4.4","Added","the","``","reuse_port","``","argument",".","..","versionchanged",":",":","6.2","Added","the","``","flags","``","argument","to","match","`",".bind_sockets","`",".","..","deprecated",":",":","6.2","Use","either","``","listen","(",")","``","or","``","add_sockets","(",")","``","instead","of","``","bind","(",")","``","and","``","start","(",")","``","."]
code: def bind(
      self,
      port: int,
      address: Optional[str] = None,
      family: socket.AddressFamily = socket.AF_UNSPEC,
      backlog: int = _DEFAULT_BACKLOG,
      flags: Optional[int] = None,
      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>`. The ``reuse_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.
  
      .. versionchanged:: 4.4
         Added the ``reuse_port`` argument.
  
      .. versionchanged:: 6.2
         Added the ``flags`` argument to match `.bind_sockets`.
  
      .. deprecated:: 6.2
         Use either ``listen()`` or ``add_sockets()`` instead of ``bind()``
         and ``start()``.
      """
      sockets = bind_sockets(
          port,
          address=address,
          family=family,
          backlog=backlog,
          flags=flags,
          reuse_port=reuse_port,
      )
      if self._started:
          self.add_sockets(sockets)
      else:
          self._pending_sockets.extend(sockets)
  
imports: import errno
  import os
  import socket
  import ssl
  from tornado import gen
  from tornado.log import app_log
  from tornado.ioloop import IOLoop
  from tornado.iostream import IOStream, SSLIOStream
  from tornado.netutil import bind_sockets, add_accept_handler, ssl_wrap_socket, _DEFAULT_BACKLOG
  from tornado import process
  from tornado.util import errno_from_exception
  import typing
  from typing import Union, Dict, Any, Iterable, Optional, Awaitable
label_desc: Use image node_id 5 for calling the TCPServer obj's underlying member method code with example usage: obj.bind(port, address, family, backlog, flags, reuse_port) without return types