Easy Networking in C (libcurl)

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024
  • 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...]

Комментарии • 117

  • @fablesfables
    @fablesfables 3 года назад +80

    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  3 года назад +5

      You're welcome! Glad I could help.

  • @critic7337
    @critic7337 2 года назад +49

    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

    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!

  • @srglmr
    @srglmr 3 года назад +4

    Your channel is a treasure , thank you

    • @JacobSorber
      @JacobSorber  3 года назад +2

      Welcome! Glad you're enjoying it.

  • @lordadamson
    @lordadamson 3 года назад +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.

  • @taskinabdur-rahman3487
    @taskinabdur-rahman3487 2 года назад +2

    This channel is incredible. Great work keep it up!

  • @marusdod3685
    @marusdod3685 3 года назад +25

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

  • @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.

  • @luismex5575
    @luismex5575 3 года назад +2

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

  • @ytsgyan2816
    @ytsgyan2816 Год назад +1

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

  • @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.

  • @AntonioAstorino
    @AntonioAstorino 3 года назад +1

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

  • @lorensims4846
    @lorensims4846 3 года назад +2

    Wheee! "easy"!!

  • @rafalmichalski4893
    @rafalmichalski4893 3 года назад +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  3 года назад +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

  • @azsxw2
    @azsxw2 2 года назад +1

    This is awesome!

  • @banshiaryal7620
    @banshiaryal7620 3 года назад +3

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

  • @comprehensivemuskrat
    @comprehensivemuskrat 3 года назад +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  3 года назад +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 3 года назад +4

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

  • @jasonzurlo1543
    @jasonzurlo1543 2 года назад +2

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

  • @subhraneelmukhopadhyay309
    @subhraneelmukhopadhyay309 Год назад +2

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

  • @eliaspfeffer
    @eliaspfeffer 3 года назад +1

    THIS IS GREAT! THANKS A LOT! WOOOOOOOOW YEAH

  • @ColonelPuttu
    @ColonelPuttu 2 года назад +1

    just found out a *legendary* channel
    very helpful thanks

  • @piecepaper2831
    @piecepaper2831 3 года назад +2

    but how i install curl and link it.

  • @krystof7059
    @krystof7059 3 года назад +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 3 года назад

      Yeah , LD_LIBRARY_PATH, RUNPATH, RPATH, LD_PRELOAD,

  • @krisdoe
    @krisdoe 3 года назад +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  3 года назад +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 3 года назад

      @@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.

  • @lordadamson
    @lordadamson 3 года назад +2

    that was awesome :D

  • @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 2 года назад

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

  • @subhashsarangi
    @subhashsarangi 3 года назад +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  3 года назад +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 3 года назад

      @@JacobSorber Thank you.

    •  3 года назад

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

    •  3 года назад

      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  3 года назад +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.

  • @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.

  • @vitacell1
    @vitacell1 3 года назад +1

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

  • @smalinux
    @smalinux 3 года назад

    You are amazing! thank you

    • @JacobSorber
      @JacobSorber  3 года назад

      You're welcome. Glad I could help.

  • @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.

  • @lordr021
    @lordr021 2 года назад

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

  • @juuamjskn2420
    @juuamjskn2420 3 года назад

    Thanks!

  • @Ryan-mn6xs
    @Ryan-mn6xs 3 года назад +1

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

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Thanks. Are you interested in any specific toolchain?

    • @Ryan-mn6xs
      @Ryan-mn6xs 3 года назад +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.

  • @willmurphy8650
    @willmurphy8650 3 года назад +1

    nice video

  • @SimGunther
    @SimGunther 3 года назад +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.

  • @elrayonegro100
    @elrayonegro100 3 года назад +2

    Where can I get that shirt? Excelent video 👌

    • @JacobSorber
      @JacobSorber  3 года назад +2

      teespring.com/stores/jacob-sorbers-store

  • @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?

  • @geethanisamanthilake9635
    @geethanisamanthilake9635 Год назад

    Thank you

  • @ButIfWeSurvive-WeHereInTheEnd
    @ButIfWeSurvive-WeHereInTheEnd Год назад

    is not working (link issue)

  • @hasithapathirage3830
    @hasithapathirage3830 3 года назад +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

  • @jeelpatel4121
    @jeelpatel4121 Год назад

    its not work on localhost

  • @cassiewinger7041
    @cassiewinger7041 3 года назад +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!

  • @lowrhyan567
    @lowrhyan567 2 года назад

    Wheres the documentation of libcurl?

  • @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

  • @user-mr3mf8lo7y
    @user-mr3mf8lo7y Год назад

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

  • @maqusss
    @maqusss 3 года назад

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

    • @Raspredval1337
      @Raspredval1337 3 года назад

      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.

  • @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).

  • @mohdatishan2090
    @mohdatishan2090 2 года назад

    Link not working!
    Low level socket programming link?

    • @JacobSorber
      @JacobSorber  2 года назад

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

    • @mohdatishan2090
      @mohdatishan2090 2 года назад

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

  • @user-sl6gn1ss8p
    @user-sl6gn1ss8p 3 года назад +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

  • @pixelPlex
    @pixelPlex 3 года назад

    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 3 года назад

      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.

  • @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.

  • @dracla26
    @dracla26 3 года назад +1

    You are such a badass.

  • @ladyViviaen
    @ladyViviaen 3 года назад +1

    c-chad

  • @leokiller123able
    @leokiller123able 3 года назад

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

  • @thinking-laaf
    @thinking-laaf 3 года назад

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

  • @georgehaake
    @georgehaake 3 года назад

    t-shirt source please.

    • @JacobSorber
      @JacobSorber  3 года назад

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

    • @georgehaake
      @georgehaake 3 года назад

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

    • @JacobSorber
      @JacobSorber  3 года назад

      @@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.

  • @radio_electronics4047
    @radio_electronics4047 7 месяцев назад

    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.

  • @sheditz4962
    @sheditz4962 3 года назад

  • @laptoprecaia.k.aagentsmith3328
    @laptoprecaia.k.aagentsmith3328 3 года назад

    .

  • @OrchidAlloy
    @OrchidAlloy 2 года назад

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

  • @LinucNerd
    @LinucNerd 3 года назад +2

    Your indentation makes me sad )': *cry*

  • @esgosar
    @esgosar Год назад

    clean this Mac screen

  • @ASAPSIDJ
    @ASAPSIDJ 3 года назад

    libcurl is bloated, too bad all the HTTP libraries suck