【问题标题】:How to get a python SocketServer to received until string is terminated with NUL如何在字符串以 NUL 终止之前接收 python SocketServer
【发布时间】:2013-02-23 02:04:57
【问题描述】:

在 Python 中,在找到 NUL 字符 (\0) 之前,我将如何编写接收字符串的 TCP SocketServer?字符串完全接收后,我需要socket继续能够接收新的字符串。

【问题讨论】:

  • @Celada 除了基本的 SocketServer (self.request.recv(1024)) 之外,我没有任何代码,老实说,我不知道该怎么做,因此,我需要帮助

标签: python sockets tcp socketserver nul


【解决方案1】:

在阅读文档时,您想使用“使用流的alternative request handler class(通过提供标准文件接口来简化通信的类似文件的对象)”:

class MyTCPHandler(socketserver.StreamRequestHandler):

一旦你有一个类似接口的文件,你可以提取字节直到你得到'\0' NUL 字符。您将阻止 read() 请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 2022-01-16
    相关资源
    最近更新 更多