Easy Networking in C (libcurl)

Sdílet
Vložit
  • čas přidán 3. 11. 2020
  • Patreon ➤ / jacobsorber
    Courses ➤ jacobsorber.thinkific.com
    Website ➤ www.jacobsorber.com
    ---
    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.jacobsorber.com
    people.cs.clemson.edu/~jsorber/
    persist.cs.clemson.edu/
    To Support the Channel:
    + like, subscribe, spread the word
    + contribute via Patreon --- [ / jacobsorber ]
    + rep the channel with nerdy merch --- [teespring.com/stores/jacob-so...]
    Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Komentáře • 117

  • @critic7337
    @critic7337 Před 2 lety +48

    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.

  • @fablesfables
    @fablesfables Před 3 lety +79

    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!!

  • @fernandoalencar3767
    @fernandoalencar3767 Před rokem +1

    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!

  • @taskinabdur-rahman3487
    @taskinabdur-rahman3487 Před 2 lety +1

    This channel is incredible. Great work keep it up!

  • @lordadamson
    @lordadamson Před 3 lety +6

    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  Před 3 lety +1

      Thanks, Adam. Glad they're still helpful.

  • @azsxw2
    @azsxw2 Před 2 lety

    This is awesome!

  • @srglmr
    @srglmr Před 3 lety +3

    Your channel is a treasure , thank you

  • @luismex5575
    @luismex5575 Před 3 lety +1

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

  • @eliaspfeffer
    @eliaspfeffer Před 2 lety

    THIS IS GREAT! THANKS A LOT! WOOOOOOOOW YEAH

  • @lordadamson
    @lordadamson Před 3 lety +1

    that was awesome :D

  • @smalinux
    @smalinux Před 3 lety

    You are amazing! thank you

  • @banshiaryal7620
    @banshiaryal7620 Před 3 lety +2

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

  • @lorensims4846
    @lorensims4846 Před 3 lety +1

    Wheee! "easy"!!

  • @Fraket
    @Fraket Před 3 lety

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

    • @JacobSorber
      @JacobSorber  Před 3 lety

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

  • @juuamjskn2420
    @juuamjskn2420 Před 3 lety

    Thanks!

  • @ytsgyan2816
    @ytsgyan2816 Před rokem

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

  • @user-ej7ss8ei2g
    @user-ej7ss8ei2g Před 3 lety +9

    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  Před 3 lety +2

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

  • @MatsGausdal
    @MatsGausdal Před 3 lety

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

  • @rishabhanand4270
    @rishabhanand4270 Před 3 lety

    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 Před 3 lety

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

  • @jasonzurlo1543
    @jasonzurlo1543 Před 2 lety +1

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

  • @marusdod3685
    @marusdod3685 Před 3 lety +24

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

  • @willmurphy8650
    @willmurphy8650 Před 3 lety +1

    nice video

  • @rafalmichalski4893
    @rafalmichalski4893 Před 3 lety +4

    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  Před 3 lety +3

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

    • @deepakmbirajdar4716
      @deepakmbirajdar4716 Před 3 lety

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

    • @JacobSorber
      @JacobSorber  Před 3 lety +2

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

    • @deepakmbirajdar4716
      @deepakmbirajdar4716 Před 3 lety

      @@JacobSorber yup

  • @dhanashreebhoyar55
    @dhanashreebhoyar55 Před 2 lety

    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.

  • @ColonelPuttu
    @ColonelPuttu Před 2 lety

    just found out a *legendary* channel
    very helpful thanks

  • @lordr021
    @lordr021 Před 2 lety

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

  • @krystof7059
    @krystof7059 Před 3 lety +3

    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 Před 3 lety

      Yeah , LD_LIBRARY_PATH, RUNPATH, RPATH, LD_PRELOAD,

  • @bobtournoux1825
    @bobtournoux1825 Před 3 lety +1

    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 Před 2 lety

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

  • @subhraneelmukhopadhyay309

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

  • @axelbagi100
    @axelbagi100 Před 3 lety +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

  • @piecepaper2831
    @piecepaper2831 Před 3 lety +1

    but how i install curl and link it.

  • @vitacell1
    @vitacell1 Před 3 lety +1

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

  • @comprehensivemuskrat
    @comprehensivemuskrat Před 3 lety +5

    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  Před 3 lety +2

      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 Před 3 lety +3

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

  • @Ryan-mn6xs
    @Ryan-mn6xs Před 3 lety +1

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

    • @JacobSorber
      @JacobSorber  Před 3 lety +1

      Thanks. Are you interested in any specific toolchain?

    • @Ryan-mn6xs
      @Ryan-mn6xs Před 3 lety +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.

  • @geethanisamanthilake9635

    Thank you

  • @krisdoe
    @krisdoe Před 3 lety +2

    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  Před 3 lety +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 Před 3 lety

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

  • @subhashsarangi
    @subhashsarangi Před 3 lety +3

    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  Před 3 lety +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 Před 3 lety

      @@JacobSorber Thank you.

    •  Před 3 lety

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

    •  Před 3 lety

      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  Před 3 lety +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.

  • @lowrhyan567
    @lowrhyan567 Před 2 lety

    Wheres the documentation of libcurl?

  • @elrayonegro100
    @elrayonegro100 Před 3 lety +2

    Where can I get that shirt? Excelent video 👌

    • @JacobSorber
      @JacobSorber  Před 3 lety +2

      teespring.com/stores/jacob-sorbers-store

  • @cassiewinger7041
    @cassiewinger7041 Před 3 lety +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  Před 3 lety

      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 Před 3 lety +1

      @@JacobSorber thats sounds fun!

  • @maqusss
    @maqusss Před 3 lety

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

    • @Raspredval1337
      @Raspredval1337 Před 3 lety

      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.

  • @amanrohilla4435
    @amanrohilla4435 Před 2 lety

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

  • @hasithapathirage3830
    @hasithapathirage3830 Před 3 lety +1

    How can we cross compile libcurl to work in ARM architecture

    • @JacobSorber
      @JacobSorber  Před 3 lety +1

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

    • @hasithapathirage3830
      @hasithapathirage3830 Před 3 lety

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

  • @ButIfWeSurvive-WeHereInTheEnd

    is not working (link issue)

  • @dracla26
    @dracla26 Před 3 lety +1

    You are such a badass.

  • @jeelpatel4121
    @jeelpatel4121 Před rokem

    its not work on localhost

  • @deepakmbirajdar4716
    @deepakmbirajdar4716 Před 3 lety

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

    • @JacobSorber
      @JacobSorber  Před 3 lety

      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 Před 3 lety

      @@JacobSorber I mean at this point 6:15

    • @JacobSorber
      @JacobSorber  Před 3 lety +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).

  • @ladyViviaen
    @ladyViviaen Před 3 lety +1

    c-chad

  • @mohdatishan2090
    @mohdatishan2090 Před 2 lety

    Link not working!
    Low level socket programming link?

    • @JacobSorber
      @JacobSorber  Před 2 lety

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

    • @mohdatishan2090
      @mohdatishan2090 Před 2 lety

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

  • @judedavis92
    @judedavis92 Před 3 lety

    Are you into the new M1 Macs?

    • @JacobSorber
      @JacobSorber  Před 3 lety +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 Před 3 lety

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

  • @SimGunther
    @SimGunther Před 3 lety +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.

  • @user-sl6gn1ss8p
    @user-sl6gn1ss8p Před 3 lety +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

  • @user-mr3mf8lo7y
    @user-mr3mf8lo7y Před rokem

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

  • @leokiller123able
    @leokiller123able Před 3 lety

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

  • @georgehaake
    @georgehaake Před 3 lety

    t-shirt source please.

    • @JacobSorber
      @JacobSorber  Před 3 lety

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

    • @georgehaake
      @georgehaake Před 3 lety

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

    • @JacobSorber
      @JacobSorber  Před 3 lety

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

  • @pixelPlex
    @pixelPlex Před 3 lety

    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 Před 3 lety

      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.

  • @sheditz4962
    @sheditz4962 Před 3 lety

  • @thinking-laaf
    @thinking-laaf Před 3 lety

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

  • @OrchidAlloy
    @OrchidAlloy Před 2 lety

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

  • @LinucNerd
    @LinucNerd Před 3 lety +2

    Your indentation makes me sad )': *cry*

  • @esgosar
    @esgosar Před rokem

    clean this Mac screen

  • @radio_electronics4047
    @radio_electronics4047 Před 5 měsíci

    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.

  • @ASAPSIDJ
    @ASAPSIDJ Před 3 lety

    libcurl is bloated, too bad all the HTTP libraries suck