You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docs: fix the command dealing function and updating TCP_Server_APIs.rst (#39)
* Docs: updating TCP_Server_APIs.rst
* Docs: updating TCP_Server_APIs.rst while the handling info APIs part has been done.
* core-code: updating TCP_Server_APIs.rst
* Docs: updating TCP_Server_APIs.rst
* core-code: fix the errors of the command dealing output result sending
* core-code: fix the error of the command dealing functions (undone)
* core-code: fix the dealing command functions
* core-code: fix the command dealing functions
3. The server allocates an ephemeral transfer port with ``palloc`` and sends
339
+
``/server_file_transfer_port <port> <client_id>`` back to the client.
340
+
4. The client connects to that transfer port and sends file metadata, including
341
+
length-prefixed filename and file size.
342
+
5. The server receives the file and writes it under ``received_files``.
343
+
344
+
Server-to-client transfer flow:
345
+
346
+
- ``file_transfer_server_recv_client_start`` is used to initiate outgoing
347
+
transfers from server to a connected client.
348
+
- The server sends transfer commands to the client socket and waits for the
349
+
client to establish the file transfer connection.
350
+
- Folder transfers are performed recursively, with each file transfer respecting
351
+
``self.max_file_transfer_thread_num`` and the configured semaphore limit.
352
+
353
+
Common file transfer helper methods include:
354
+
355
+
- ``file_transfer_server_recv_server_start``: receives file data from a client.
356
+
- ``file_transfer_server_recv_client_start``: sends a file or folder to a client.
357
+
- ``file_transfer_mode``: performs the low-level client-side transfer handshake.
358
+
- ``file_transfer_mode_recv``: performs the low-level receive-side transfer handshake.
359
+
360
+
Port allocation API
361
+
-------------------
362
+
363
+
When ``is_hand_alloc_port`` is ``True``, the server uses manual port allocation
364
+
and lock files to avoid conflicts across multiple server instances. The relevant
365
+
methods are:
366
+
367
+
- ``alloc_port``: allocate a port range for the server.
368
+
- ``free_port``: release the allocated port range when the server stops.
369
+
- ``hand_alloc_port`` and ``hand_free_port``: internal helpers used by the manual allocation flow.
370
+
371
+
This mode is useful when the server must reserve a controlled range of ports
372
+
for client-file transfers or when multiple server processes share the same host.
373
+
374
+
TCP Server helper APIs
375
+
----------------------
376
+
377
+
The following helper methods are also available on ``TCP_Server_Base``:
378
+
379
+
- ``broadcast(self, message, exclude_client=None)``: broadcast a message to all connected clients.
380
+
- ``send_msg_to_specific_client(self, message)``: send a message to one or more specific clients by address.
381
+
- ``submit_task(self, func, *args, **kwargs)``: submit work to the server's internal thread pool.
382
+
- ``create_temporary_server(self, handler, port=None, max_connections=1)``: start a temporary TCP server for short-lived tasks.
383
+
- ``create_temporary_client(self, server_host, server_port, bind_port=None, on_data=None)``: start a temporary client that receives data asynchronously.
384
+
385
+
These APIs make it easier to extend the base TCP server for custom command handling,
0 commit comments