【问题标题】:How to send message to tcp server using pycurl如何使用 pycurl 向 tcp 服务器发送消息
【发布时间】:2018-07-29 07:09:05
【问题描述】:

我试图使用 pycurl 卷曲一个 tcp 服务器

class Detector():
    def __init__(self, api_addr="tcp://localhost:8000"):
        self.c = pycurl.Curl()
        self.c.setopt(self.c.URL, api_addr)

    def close_connection(self):
        self.c.close()

    def img_encode(self, img):
        _, img_encoded = cv2.imencode('.jpg', img)
        return img_encoded.tostring()

    def detect(self, img):
        encoded_msg = self.img_encode(img)
        self.c.setopt(self.c.POSTFIELDS, encoded_msg)
        return self.c.perform()

但它报告pycurl.error: (1, 'Protocol "tcp" not supported or disabled in libcurl') 有什么解决方案或者 curl tcp 服务器不合适?

【问题讨论】:

  • 不,不要为此使用 curl。 Curl 旨在用于在 TCP 之上运行的特定标准协议,尤其是 HTTP。
  • @nos 感谢您的回答:)。本来打算通过终端 curl 到服务器的,我想这种情况下我只能使用 tcp 客户端套接字。

标签: curl pycurl


【解决方案1】:

https://curl.haxx.se/libcurl/c/CURLOPT_PROTOCOLS.html 没有说 libcurl 有一个“tcp”协议。

另外,TCP 不是一种协议,就像 HTTP 是一种协议一样。如果您只是想读取数据并将数据写入 TCP 服务器,您可以直接使用 TCP 套接字,因为您只需在其上调用 readwrite

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2019-01-21
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多