Easy Networking in C (libcurl)

Поділитися
Вставка
  • Опубліковано 13 січ 2025
  • Patreon ➤ / jacobsorber
    Courses ➤ jacobsorber.th...
    Website ➤ www.jacobsorbe...
    ---
    Easy Networking in C (libcurl) // Network programming is fun, but it can be complicated and sometimes you just want to quickly add some communication to your programs, or add some download functionality. This programming tutorial shows you how to do common networking or network programming tasks in C the easy way, with libcurl.
    Related Videos:
    Socket Client: • How to build a web cli...
    Other network programming videos: • Network Programming
    Makefile videos: • Makefile-Related Videos
    ***
    Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
    About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
    More about me and what I do:
    www.jacobsorbe...
    people.cs.clem...
    persist.cs.clem...
    To Support the Channel:
    like, subscribe, spread the word
    contribute via Patreon --- [ / jacobsorber ]
    rep the channel with nerdy merch --- [teespring.com/...]
    Source code is also available to Patreon supporters. --- [jsorber-youtub...]

КОМЕНТАРІ • 119

  • @fablesfables
    @fablesfables 4 роки тому +82

    Hey man, just want to say as fellow university student that programs in C/C++ every single day, your youtube videos have been gold for bringing some 21st century C knowledge onto youtube. The way you layout your videos and your explanations with clear concise examples allow me to really understand the concepts well and have enough to get going myself. Thank you so much and keep making awesome content!!

    • @JacobSorber
      @JacobSorber  4 роки тому +5

      You're welcome! Glad I could help.

  • @critic7337
    @critic7337 3 роки тому +53

    Great video - but to any students watching, don't let his rant about "doing it yourself" fool you - 99% of professional developers do not write their own HTTP/FTP/etc. clients for new projects. Using a library for something like this is normal and good, especially one that is as well documented and tested as libcurl.

  • @fernandoalencar3767
    @fernandoalencar3767 2 роки тому +2

    Wow super quick and fast for newbies like me to learn..
    Of course there are cons and pros to using this library but for beginners in C that are still exploring the language, it’s really amazing!

  • @marusdod3685
    @marusdod3685 4 роки тому +26

    if you execute the curl command with the option --libcurl it will dump the source code

  • @lordadamson
    @lordadamson 4 роки тому +7

    Your videos also serve as references :D Here I am after several months coming back to this video because I'm implementing something that needs libcurl. You sir are awesome :D

    • @JacobSorber
      @JacobSorber  3 роки тому +1

      Thanks, Adam. Glad they're still helpful.

  • @srglmr
    @srglmr 4 роки тому +4

    Your channel is a treasure , thank you

    • @JacobSorber
      @JacobSorber  4 роки тому +2

      Welcome! Glad you're enjoying it.

  • @taskinabdur-rahman3487
    @taskinabdur-rahman3487 3 роки тому +2

    This channel is incredible. Great work keep it up!

  • @rishabhanand4270
    @rishabhanand4270 3 роки тому +1

    Okay, so by default any response headers are omitted, that's really handy. Not many people need to read GET 200 OK HTTP/1.1, that is really useful. If you need it, you can use it. That's probably why those functions are having _easy_ in them. Beautiful library.

  • @ytsgyan2816
    @ytsgyan2816 2 роки тому +1

    Hi Jacob,also, please do mention online tutorial for beginner to advanced lesson of using libcurl in C.

  • @luismex5575
    @luismex5575 4 роки тому +2

    Please make more videos about this... they are great

  • @rafalmichalski4893
    @rafalmichalski4893 4 роки тому +5

    Nice video Jacob as always. I have question could you make video based on curl to show how to use some example REST API with post / get / put methods ?

    • @JacobSorber
      @JacobSorber  4 роки тому +3

      Sure. I'll add it to the future video topic list.

    • @deepakmbirajdar4716
      @deepakmbirajdar4716 3 роки тому

      @@JacobSorber Is this available? and please let us know how to get status code.

    • @JacobSorber
      @JacobSorber  3 роки тому +2

      @@deepakmbirajdar4716 Is the source code available? Yes, through Patreon. And, by "status code" do you mean the HTTP status code?

    • @deepakmbirajdar4716
      @deepakmbirajdar4716 3 роки тому

      @@JacobSorber yup

  • @jimmymontenegro8517
    @jimmymontenegro8517 3 місяці тому

    Gracias, me va a servir mucho para lo que estoy aprendiendo.

  • @comprehensivemuskrat
    @comprehensivemuskrat 4 роки тому +6

    When you’re writing a callback or interacting with a callback heavy library, what’s a fast way to find the callback signature and make sure you’re getting the signature right?

    • @JacobSorber
      @JacobSorber  4 роки тому +3

      The signature should be listed in the library documentation. If not, you can check the header file where the function that takes the callback is defined. The signature should be there, too.

    • @Raspredval1337
      @Raspredval1337 4 роки тому +4

      every function signature is a data type, so if ur IDE shows the type aliases, it would show u the required function signature

  • @user-ej7ss8ei2g
    @user-ej7ss8ei2g 3 роки тому +10

    I love your videos so much, seriously. Your list and queue videos are really fun as well.
    libcurl has got to be one of the most messy or perhaps OVERLY abstracted APIs ever. It just ends up super non-intuitive to me.

    • @JacobSorber
      @JacobSorber  3 роки тому +2

      Not as "easy" as you would like? 😀 Thanks for the support.

  • @krisdoe
    @krisdoe 4 роки тому +3

    Nice video. Indeed, this is the easy way to do quick and dirty networking in C. One question still remains - is how portable is thit between different Linux distributions? I already tried to use it on DEB-based ones (works great). But for RPM-based, somehow is causing troubles finding the library. It would be nice if get better explanation how we can make sure the application we write is portable.

    • @JacobSorber
      @JacobSorber  4 роки тому +1

      Hmm... I haven't seen that, but then again, these days most of my work is either on macOS or ubuntu (seems to work fine on both). If you can send me more details about the issue you're seeing, I'll take a look. Always looking for interesting video ideas. Thanks.

    • @krisdoe
      @krisdoe 4 роки тому

      @@JacobSorber I decided to drop you a mail. I don't want to flood the comment section. I hope you don't mind. Maybe after everything is clarified we could share the information with everybody here.

  • @jasonzurlo1543
    @jasonzurlo1543 3 роки тому +2

    How do you get the curl library? I went on the website, but I can only find an executable curl program.

  • @AntonioAstorino
    @AntonioAstorino 3 роки тому +1

    I pushed the "like" button at 1:07 - LOL

  • @krystof7059
    @krystof7059 4 роки тому +4

    video on linking libraries please? :D I know how to link in ide but not in code editor... Do you have all your library files in same folder?

    • @vikramfugro3886
      @vikramfugro3886 4 роки тому

      Yeah , LD_LIBRARY_PATH, RUNPATH, RPATH, LD_PRELOAD,

  • @banshiaryal7620
    @banshiaryal7620 4 роки тому +3

    Great work as usual. Your videos are so helpful.
    Would you mind syncing your content over on LBRY? Trying to stay away from UA-cam.

  • @bobtournoux1825
    @bobtournoux1825 3 роки тому +2

    The curl library is certainly a life saver when there isn't time to do the low level socket stuff. Do you have any idea how much of a performance hit using curl instead of the low level socket programming might be? For my case it would be just using curl to to some simple GET and POST calls, but there might be 10 to 20 calls per second. Just wandering if using curl can handle that kind of load.

    • @OrchidAlloy
      @OrchidAlloy 3 роки тому

      It's not as if it's gonna be slower than every Node JS app people use nowadays

  • @ColonelPuttu
    @ColonelPuttu 2 роки тому +1

    just found out a *legendary* channel
    very helpful thanks

  • @subhashsarangi
    @subhashsarangi 4 роки тому +4

    Awesome video... However I'm confused by the usage of curl_easy_setopt function. On line 33 the 3rd arg to this function was a string. But on line 34 it was a function. How is that possible in C?

    • @JacobSorber
      @JacobSorber  4 роки тому +3

      Thanks. They're both pointers. A character pointer and a function pointer are both just addresses. But, this function is implemented as a variadic function (kind-of like printf). I have a video on variadics, if you're interested.

    • @subhashsarangi
      @subhashsarangi 4 роки тому

      @@JacobSorber Thank you.

    •  4 роки тому

      @@JacobSorber I mean, the function may receive void*, but how does curl knows it's a char* or a function pointer?

    •  4 роки тому

      I guess it depends on the opt argument, but it still may get in trouble if the pointer passed is not of a type it expects.

    • @JacobSorber
      @JacobSorber  4 роки тому +1

      It determines what it is based on the option you specify. For URL, it looks for a string. For the other, it looks for a function pointer.

  • @piecepaper2831
    @piecepaper2831 3 роки тому +2

    but how i install curl and link it.

  • @subhraneelmukhopadhyay309
    @subhraneelmukhopadhyay309 2 роки тому +2

    I'm getting this error "Makefile:10: *** missing separator. Stop." when i type make

    • @larrysmall3521
      @larrysmall3521 3 місяці тому

      Sounds like you have a space instead of a Tab on line 10 in the makefile.

  • @vitacell1
    @vitacell1 3 роки тому +1

    Can be great some simple game in terminal with p2p game networking.

  • @dhanashreebhoyar55
    @dhanashreebhoyar55 2 роки тому

    Can I use libcurl in Apache web server module? I tried but I am always getting undefined reference to libcurl API. Can you please make videos on apache+libcurl.

  • @eliaspfeffer
    @eliaspfeffer 3 роки тому +1

    THIS IS GREAT! THANKS A LOT! WOOOOOOOOW YEAH

  • @azsxw2
    @azsxw2 3 роки тому +1

    This is awesome!

  • @lordr021
    @lordr021 2 роки тому

    I have the json, how to iterate response string readBuffer, containing a json -> curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

  • @hasithapathirage3830
    @hasithapathirage3830 4 роки тому +1

    How can we cross compile libcurl to work in ARM architecture

    • @JacobSorber
      @JacobSorber  3 роки тому +1

      I haven't tried this, but it would surprise me if someone hasn't. Socket code is fairly portable.

    • @hasithapathirage3830
      @hasithapathirage3830 3 роки тому

      @@JacobSorber yeah I got it done, thank you for the reply

  • @lorensims4846
    @lorensims4846 3 роки тому +2

    Wheee! "easy"!!

  • @axelbagi100
    @axelbagi100 3 роки тому +1

    Hey man, I need some help
    The simple curl_easy_setopt(curl, CURLOPT_URL, "https:....") throws an unsupported protocol error
    I have installed libcurl this way:
    Downloaded the latest zip, extracted it
    In the extract location in cmd (Im on win10) used this code:
    cmake -G "MinGW Makefiles" -S . -B . -DCMAKE_INSTALL_PREFIX=F:\MinGW\mingw64\x86_64-w64-mingw32
    Then *mingw32-make all* and *mingw32-make install*
    Everything is fine but the program doesnt work
    If I simply use curl from the cmd like this: *curl CURLOPT_URL **www.youtube.com* it works fine
    What could be a problem? Cant find an answer anywhere

  • @Massimus888
    @Massimus888 3 роки тому

    Thanks! Do you recommend libxml2 for parsing the html document?

  • @lowrhyan567
    @lowrhyan567 3 роки тому

    Wheres the documentation of libcurl?

  • @elrayonegro100
    @elrayonegro100 4 роки тому +2

    Where can I get that shirt? Excelent video 👌

    • @JacobSorber
      @JacobSorber  4 роки тому +2

      teespring.com/stores/jacob-sorbers-store

  • @Ryan-mn6xs
    @Ryan-mn6xs 4 роки тому +1

    Great video as usual! Any plans to do one on Toolchains?

    • @JacobSorber
      @JacobSorber  4 роки тому +1

      Thanks. Are you interested in any specific toolchain?

    • @Ryan-mn6xs
      @Ryan-mn6xs 4 роки тому +2

      @@JacobSorber Kind of niche, but musl on mips. Linux to FreeBSD would be interesting as well. More generically the idea of cross-compilation and emulation (qemu) would be a cool topic.

  • @SimGunther
    @SimGunther 4 роки тому +1

    Postman and Insomnia are capable of creating c code that calls libcurl functions based on endpoint data in the postman request.
    Learn how the libraries work through documentation first before naively using this generated code in your project.

  • @lordadamson
    @lordadamson 4 роки тому +2

    that was awesome :D

  • @deepakmbirajdar4716
    @deepakmbirajdar4716 3 роки тому

    How to disable printing the response automatically. How do we get the status code.

    • @JacobSorber
      @JacobSorber  3 роки тому

      For disabling the printing, just remove the print statements. I'm doing the printing, not libcurl. For the response code, check this out. curl.se/libcurl/c/CURLINFO_RESPONSE_CODE.html

    • @deepakmbirajdar4716
      @deepakmbirajdar4716 3 роки тому

      @@JacobSorber I mean at this point 6:15

    • @JacobSorber
      @JacobSorber  3 роки тому +1

      @@deepakmbirajdar4716 Ok. The video shows you how to specify a "write function" and that allows you to replace the default behavior (turning it off).

  • @cassiewinger7041
    @cassiewinger7041 4 роки тому +1

    Hi, thanks for the tutorials. #awesome.
    can you make a tutorial about a simple encrypted chat? just a server an a client having sending and receiving encrypted texts?
    thanks.

    • @JacobSorber
      @JacobSorber  3 роки тому

      Interesting. Maybe. What sort of encryption would you be interested in? Just something symmetric (AES?) with a shared key, or are looking for full Public Key/Private Key stuff?

    • @JohnDoe-ym2oy
      @JohnDoe-ym2oy 3 роки тому +1

      @@JacobSorber thats sounds fun!

  • @maqusss
    @maqusss 4 роки тому

    Is there a problem with print because the charset is UTF-8 ?

    • @Raspredval1337
      @Raspredval1337 4 роки тому

      ASCII translates into the UTF8 without any change, so every English text is ok, but local characters such as Cyrillic or Eastern Europe would be represented as character pairs or triplets, so standard printf would just type some random stuff instead.

  • @smalinux
    @smalinux 4 роки тому

    You are amazing! thank you

    • @JacobSorber
      @JacobSorber  4 роки тому

      You're welcome. Glad I could help.

  • @amanrohilla4435
    @amanrohilla4435 3 роки тому

    I'm getting an error with url, SSL certificate problem: unable to get local issuer certificate how to solve it. I'm using windows

  • @Fraket
    @Fraket 3 роки тому

    Thanks for this. Great video. Just bought one of those shirts, btw :)

    • @JacobSorber
      @JacobSorber  3 роки тому

      Thanks! Glad I could help you upgrade your wardrobe. 😀I appreciate the support.

  • @ButIfWeSurvive-WeHereInTheEnd

    is not working (link issue)

  • @mohdatishan2090
    @mohdatishan2090 3 роки тому

    Link not working!
    Low level socket programming link?

    • @JacobSorber
      @JacobSorber  3 роки тому

      Weird. Maybe YT changed the link? It's pretty old. I just updated. Let me know if that works for you.

    • @mohdatishan2090
      @mohdatishan2090 3 роки тому

      @@JacobSorber Yeah, that works!
      BTW Huge Respect for replying....

  • @juuamjskn2420
    @juuamjskn2420 4 роки тому

    Thanks!

  • @willmurphy8650
    @willmurphy8650 4 роки тому +1

    nice video

  • @jeelpatel4121
    @jeelpatel4121 Рік тому

    its not work on localhost

  • @judedavis92
    @judedavis92 3 роки тому

    Are you into the new M1 Macs?

    • @JacobSorber
      @JacobSorber  3 роки тому +2

      Too soon to say. There have been some benefits to having my Linux boxes and Macs on the same CPUs. I hope we don't lose ground there, but diversity in the market can be a good thing. So, I'm cautiously optimistic, and hoping for the best.

    • @judedavis92
      @judedavis92 3 роки тому

      @@JacobSorber hey I was literally watching one of your early websockets videos. Nice channel, keep it going.

  • @geethanisamanthilake9635
    @geethanisamanthilake9635 Рік тому

    Thank you

  • @pixelPlex
    @pixelPlex 4 роки тому

    Very useful for developers of C libraries to keep in mind that there are different programming languages other than C that can use C libraries (eg Kotlin - kotlinlang.org/docs/reference/native/c_interop.html ). C library developers need to design APIs in a way that can be usable for other programming languages (eg don't use macros as part of the public API).
    Here is a sample project that uses libcurl: gitlab.com/napperley/curl-example

    • @noxabellus
      @noxabellus 4 роки тому

      Macro usage isnt going to stop anyone from making an ffi wrapper for your library; In fact there isnt really much you can do that precludes an ffi wrapper for your c library. The universal compatibility of C is exactly why other languages have ffi for it. On the contrary, you shouldn't hamper the lib consumer's experience in primary language just to simplify the process of writing a wrapper for it. Things like defines for constant expressions dont have good alternatives in C and you shouldn't avoid them. Translating them to the wrapper language is much simpler than working around the lack of them in c.

  • @user-mr3mf8lo7y
    @user-mr3mf8lo7y 2 роки тому

    All good. Buttttt linking Curl statically with your program is really pain. You have been warned.

  • @leokiller123able
    @leokiller123able 3 роки тому

    If you don't want to get annoyed by the "easy" you can just do #define curl_ curl_easy_

  • @user-sl6gn1ss8p
    @user-sl6gn1ss8p 4 роки тому +1

    This has nothing to do with the topic at hand, but does anyone know of some examples of test driven development in practice, at some depth? I like the idea but have a hard time seeing how one actually goes about it : p

  • @georgehaake
    @georgehaake 4 роки тому

    t-shirt source please.

    • @JacobSorber
      @JacobSorber  4 роки тому

      You can get it from the merch store, should show up right under the video.

    • @georgehaake
      @georgehaake 4 роки тому

      @@JacobSorber Don't see it. Found it via search.

    • @JacobSorber
      @JacobSorber  4 роки тому

      @@georgehaake So, strange. I wonder why some people don't see it on YT. Glad you were able to find it. Thanks for the support.

  • @thinking-laaf
    @thinking-laaf 3 роки тому

    FTP isn't secure, so it doesn't matter the password is secure or not.

  • @dracla26
    @dracla26 3 роки тому +1

    You are such a badass.

  • @ladyViviaen
    @ladyViviaen 4 роки тому +1

    c-chad

  • @radio_electronics4047
    @radio_electronics4047 11 місяців тому

    This video is not that helpful because you do not store the data in a variable
    and are not able to use that data in the rest of your program, you just have it in a callback function.
    And getting that data into a variable is the most complicated part in libcurl.

  • @OrchidAlloy
    @OrchidAlloy 3 роки тому

    It's almost as if curl is making fun of you for doing things the easy way

  • @LinucNerd
    @LinucNerd 4 роки тому +2

    Your indentation makes me sad )': *cry*

  • @esgosar
    @esgosar 2 роки тому

    clean this Mac screen

  • @laptoprecaia.k.aagentsmith3328
    @laptoprecaia.k.aagentsmith3328 3 роки тому

    .

  • @sheditz4962
    @sheditz4962 3 роки тому

  • @ASAPSIDJ
    @ASAPSIDJ 4 роки тому

    libcurl is bloated, too bad all the HTTP libraries suck