3

I developed a program that makes parameters tracking. I want to inform a server with a http message over udp when a parameter value changes.

I want to use libcurl for that. Does libcurl able to send a http message over UDP?

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
  • 1
    You're talking about different protocol layers here. `http` is a `TCP`/`IP` based protocol, where `UDP` intentionally misses the `TCP` part! Though libcurl seems to [support UDP](http://curl.haxx.se/mail/lib-2011-03/0204.html). – πάντα ῥεῖ Sep 05 '14 at 17:17
  • 2
    libcurl supports UDP for the UDP-based protocol TFTP, not for HTTP. – Daniel Stenberg Sep 05 '14 at 17:23

2 Answers2

4

No it doesn't. For HTTP, libcurl only supports TCP or Unix domain socket. It could possibly be something to add in a future.

(libcurl supports UDP transfers for a few other protocols.)

HTTP/3

HTTP/3 is done over QUIC which is done over UDP, so strictly speaking if you use curl to do a HTTP/3 transfer it will use UDP. But I'm just guessing that is not what this question is about...

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
  • Isn't it questionable trying to send HTTP messages via UDP? There won't be anything controlling the transmission and there aren't responses at all. – πάντα ῥεῖ Sep 05 '14 at 17:31
  • @DanielStenberg Is it possible to use libcurl to send UDP messages (not http messages) ? – MOHAMED Sep 08 '14 at 08:12
  • I find the wording of this answer misleading. In the context of the question, it makes sense; but one could easily assume from that answer that cURL doesn't support anything but HTTP over TCP. – 7heo.tk Jun 13 '16 at 08:34
  • 1
    I tried to clarify now, and these days it supports HTTP over unix domain sockets too! =) – Daniel Stenberg Jun 13 '16 at 08:55
  • Good move, I didn't know about UNIX sockets; that might be useful. Thanks for double checking! – 7heo.tk Jun 13 '16 at 10:01
  • @MOHAMED Yes, but you cannot send any packet via UDP: you're limited to what protocols cURL supports. One example is TFTP: it uses the UDP protocol, but you'll be forced to use the TFTP protocol in addition. If you want to send hand-crafted packets over the UDP protocol, I'd recommend to simply use sockets; whenever possible. – 7heo.tk Jun 13 '16 at 10:13
2

HTTP could in theory be used over a different protocol than TCP (this case is mentioned in RFC2616), but it needs to be a reliable protocol, that is a protocol which provides guaranteed delivery, must keep the order of messages and must detect duplicates. Plain UDP does not provide these things and thus it is not possible to use HTTP over plain UDP and thus libcurl does not provide it.

If you are interested in a protocol with a syntax close to HTTP, but with support of UDP, then have a look at SIP which is used for VoIP.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172