0

I was trying to curl a tcp server using pycurl

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()

But it reports that pycurl.error: (1, 'Protocol "tcp" not supported or disabled in libcurl') Is there any solution or it's not proper to curl a tcp server?

Jiang Wenbo
  • 469
  • 2
  • 9
  • 20
  • no, don't use curl for that. Curl is meant to be used for particular standard protocols that run on top of TCP, in particular HTTP. – nos Jul 29 '18 at 07:11
  • @nos Thanks for your answer :). I was intended to curl to the server through terminal, I guess I could only use tcp client socket in this case. – Jiang Wenbo Jul 29 '18 at 11:43

1 Answers1

0

https://curl.haxx.se/libcurl/c/CURLOPT_PROTOCOLS.html does not say anything about libcurl having a "tcp" protocol.

Also, TCP is not a protocol in the same sense as HTTP is a protocol. If you simply want to read and write data to a TCP server, you can use a TCP socket directly as all you'd be doing is calling read and write on it.

D. SM
  • 13,584
  • 3
  • 12
  • 21