Start a socket server, call back for each client connected. The first parameter, `client_connected_cb`, takes two parameters: client_reader, client_writer. client_reader is a StreamReader object, while client_writer is a StreamWriter object. This parameter can either be a plain ca
(client_connected_cb, host=None, port=None, *,
limit=_DEFAULT_LIMIT, **kwds)
| 52 | |
| 53 | |
| 54 | async def start_server(client_connected_cb, host=None, port=None, *, |
| 55 | limit=_DEFAULT_LIMIT, **kwds): |
| 56 | """Start a socket server, call back for each client connected. |
| 57 | |
| 58 | The first parameter, `client_connected_cb`, takes two parameters: |
| 59 | client_reader, client_writer. client_reader is a StreamReader |
| 60 | object, while client_writer is a StreamWriter object. This |
| 61 | parameter can either be a plain callback function or a coroutine; |
| 62 | if it is a coroutine, it will be automatically converted into a |
| 63 | Task. |
| 64 | |
| 65 | The rest of the arguments are all the usual arguments to |
| 66 | loop.create_server() except protocol_factory; most common are |
| 67 | positional host and port, with various optional keyword arguments |
| 68 | following. The return value is the same as loop.create_server(). |
| 69 | |
| 70 | Additional optional keyword argument is limit (to set the buffer |
| 71 | limit passed to the StreamReader). |
| 72 | |
| 73 | The return value is the same as loop.create_server(), i.e. a |
| 74 | Server object which can be used to stop the service. |
| 75 | """ |
| 76 | loop = events.get_running_loop() |
| 77 | |
| 78 | def factory(): |
| 79 | reader = StreamReader(limit=limit, loop=loop) |
| 80 | protocol = StreamReaderProtocol(reader, client_connected_cb, |
| 81 | loop=loop) |
| 82 | return protocol |
| 83 | |
| 84 | return await loop.create_server(factory, host, port, **kwds) |
| 85 | |
| 86 | |
| 87 | if hasattr(socket, 'AF_UNIX'): |
searching dependent graphs…