learn network programming in c, but without all those pesky sockets

preview_player
Показать описание
When learning to program, one of the first advanced projects you'll get is a networking project. You may even have this in your classes right now where you need to send data from a client to a server and vice versa. This isn't an easy task for a new programmer, and while you should definitely learn the C networking API for Linux or Windows, there's an easier way to do this.

ZeroMQ or ZMQ is a message queue library that provides an abstraction over the socket API to make networking easier in C, as well as many other languages. In this video, we go over a basic implementation of the ZMQ library, using a request response schema for a basic networking application.

🏫 COURSES 🏫

🔥🔥🔥 SOCIALS 🔥🔥🔥
Рекомендации по теме
Комментарии
Автор

Leave a comment, let me know what YOUR favorite networking library is!

LowLevel-TV
Автор

What’s wrong with the linux sockets API? It’s actually very logical and clean, I don’t understand how this is any better.

kerboplaytv
Автор

Awesome video, that PTSD from the socket API got me looking for alternatives. Thank you very much!

xgerbot_
Автор

a week ago i had no experience in c and 2 days later i made a web server hosting a simple api using winsock2 thanks to discovering this channel! i really enjoy your c videos especially!

nuttolum
Автор

This is sweet. Sockets is fine but I'm already bangin away at some crazy stuff with this API. Thanks L3!

MusingsOfaComputerProgrammer
Автор

What I like about sockets are the IO Strategy, especially multiplexing, to handle multiple sockets, using select option to select only the sockets that has pending data, and IOCTL where you can check the state of a socket or set a block state to a socket.

For socket strategy there is IOStrategy, Async and Multi-threaded,
- IO strategy uses a single thread where it selects sockets that have pending data to handle them,
- Async uses opens and closes or uses a thread-pool to handle sockets in separate threads, if you have to synchronize data received from the sockets you have to synchronize it manually
- Multi-threaded handles sockets in separate threads, in my opinion multi-threaded should be avoided, it is the easiest to handle but the slowest when handling a lot of clients,
- There is also an hybrid mode where using IO Strategy in separate threads as socket channels, for example

I also wrote 3 layers of abstraction for the socket library in c++, Socket->DataSocket ->Listening and Connection socket, after this I wrote the communication protocol, because send and recv, does not ensure, you will receive the full message, because if the message is too big, it will be broken into chunks or receive part of the next message, especially if you have blocking turned off per socket

A good socket library should have options to use their own strategy(IOStrategy, Async, Multi-threaded, etc, ) to handle sockets, an easy to use listening and connection socket, also a communication protocol,

ghostlucian
Автор

I have been using ZMQ for awhile now to build distributed computing software for Manufacturing and Execution Systems and it works really great... can do anything from normal pub sub and req resp patterns to esoteric patterns like radio dish and multi stage compute pipelines. Maybe someday someone can show it working on an ESP32 or similar...

MellexLabs
Автор

Before investing your time in 0MQ, here are a few considerations:
* The sockets API is well documented, and underlies all IP based networking software. You'll need to learn it sooner or later.
* 0MQ is not a replacement for the sockets API; rather, 0MQ is a pub/sub networking toolkit built on top of the sockets API.
* NATS is a similar pub/sub toolkit which is widely used in industry, but with better intrinsic security than OMQ.
* If you want to write networking software which is as reliable as possible, you will need to learn how to use non-blocking I/O with a single thread. 0MQ (and NATS) kick this can down the road by using seperate threads under the hood to buffer messages.

trghtGuy
Автор

I tried to use zmq once in the project, but realized that it does not guarantee delivery on its own. I read parts of zmq source and it appears to me that data, which was sent from zmq and is then in OS network buffer, may get lost when TCP connection will break. Zmq will do re-connection for you, but data from OS buffer may never get to the destination. So without implementing some acknowledge protocol over zmq messages I could not be sure that data put to zmq will be actually delivered. I tried to do that and it was like re-implementing TCP in simplified form. Another solution I came up was to listen to socket events (or whatever it was called) and reacting on disconnections in some way.

arion_vulgaris
Автор

Hi, wouldn't the zsock_destroy function in server.c never be called ? Wouldn't it be better to setup a function whenever a SIGINT is received that destroys the socket and terminate the server ?

orko
Автор

It's nice but so basic. Maybe the rest of the library is more advanced, like for example handle multiple streams concurrently (have a context for the underlying socket) or asynchronous networking like select/epoll.

unperrier
Автор

THANKS for this video, im looking this kind of video for ages

edinetgrunhed
Автор

I used ~5 years ago zmq for a RADAR-System to transmit processed I/Q-Data to a websocket-server. From there on, the clients received the data via websockets inside the provided web application.

deadeyea
Автор

Interesting how zmq have stuff running post main to detect non freed resources. Maybe that's a signal handler or something, will grep for dangling in the source when I have an opportunity. Thanks for the video!

miklov
Автор

Awesome! Looks promising for embedded devs.

rodolfoblasser
Автор

Thanks man, awesome vid.
I've just started to use this library to deploy C code directly to a Raspberry Pi robot of mine.
it's super useful. Keep Rocking \m/

ivelinkarageorgiev
Автор

I love this video. Thank you so much. Now i want MORE SOCKET RELATED PROJECTS

Modus_Pwnin
Автор

In my day job (sadly) I do a lot of web development... this seems very familiar. Nice.

edgeeffect
Автор

It would be nice a Demo using libcurl library and then integrates with a json parser library 😉. Great video 🙏

alexandrohdez
Автор

Isn't the socket freed by the OS when a process dies? I always thought it's just a good practice to clean everything, but not strictly needed

sergiocoder