How to write a multithreaded server in C (threads, sockets)

How to write a multithreaded server in C (threads, sockets)

Jacob Sorber

4 года назад

131,840 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@elliotalderson9889
@elliotalderson9889 - 30.08.2023 11:59

super cool tutorial. Thank you so much!

Ответить
@Runeite51
@Runeite51 - 19.08.2023 20:35

most unexpected programming video intro

Ответить
@tw7522
@tw7522 - 12.08.2023 12:36

This code is horrible. Seriously, you should take the video down.

Ответить
@user-xb3ln7yu9b
@user-xb3ln7yu9b - 15.05.2023 06:20

How to terminate threads explicit?

Ответить
@anwarpenn
@anwarpenn - 09.04.2023 03:39

Thank you so much for sharing! very insightful!

Ответить
@pikimk6167
@pikimk6167 - 09.03.2023 04:51

Hi Jacob, i love your videos and could you do a libuv tutorial? I think it will be a fun topic to watch.

Ответить
@gurjaschawla1019
@gurjaschawla1019 - 02.03.2023 07:03

Hi, I can't find the source code on Patreon . can someone send me . Will be very appreciated , Thanks

Ответить
@sushmitagoswami2033
@sushmitagoswami2033 - 11.02.2023 10:31

Much respect to you sir! Thanks for sharing the knowledge

Ответить
@vishwaspaikra795
@vishwaspaikra795 - 26.01.2023 09:04

is it a good idea to give each client a thread? is it dangerous? Is it a good idea to handle client request with accept or epoll and assign a thread for a specific task?
which is better?

Ответить
@Nothing-dq5rx
@Nothing-dq5rx - 31.10.2022 23:55

Priority Multithreading tcp please

Ответить
@juanmamani2110
@juanmamani2110 - 25.10.2022 20:36

Exactly what I was looking for. Thanks for sharing!
Which c compiler did you use?

Ответить
@techtechlearn3438
@techtechlearn3438 - 28.09.2022 13:40

how many cores/threads does your "server" (which I presume it's the actual host pc you are using) have, just so that I can image how many threads can actually run in parallel at once? Thank you!!!

Ответить
@MaiHappyBanda
@MaiHappyBanda - 29.08.2022 09:29

i thought its a vlog

Ответить
@ragnarlothbrok367
@ragnarlothbrok367 - 05.08.2022 01:23

too hard to understand

Ответить
@dhruvandangar8005
@dhruvandangar8005 - 05.04.2022 07:15

The intro was just lit.
Rainy season touch my heart.

Ответить
@gavinjakubik6717
@gavinjakubik6717 - 23.03.2022 23:24

Very well done video

Ответить
@eduardonolla9470
@eduardonolla9470 - 02.02.2022 01:20

I have been trying to get my threads running for 3 whole days. After using your method of passing the sockets as pointers my problem was solved. Thank you so much

Ответить
@karthikp3329
@karthikp3329 - 14.11.2021 12:54

Please correct me if I am wrong:

If there is pointer to a dynamically allocated memory in calling function and it is passed as an argument to called function (as you did in the case of handleConnection() function), will it not cause a dangling pointer in calling function if the memory is freed in called function?

I think it's better to free the memory in calling function (or parent thread) and to be safer, after child thread joining. I guess the pointer in new thread function will have no effect once the function returns and frame is removed from function call stack.

Ответить
@enioladare4967
@enioladare4967 - 31.10.2021 17:46

You were a professor at botho right?

Ответить
@mahamanebana4410
@mahamanebana4410 - 30.07.2021 04:10

I'm from Africa. Really appreciate your work

Ответить
@leokiller123able
@leokiller123able - 17.07.2021 13:41

Would it make it faster if we use fork() instead of threads?

Ответить
@adityavikram5176
@adityavikram5176 - 22.05.2021 12:08

Awesome video!!

Ответить
@foxred2380
@foxred2380 - 19.03.2021 13:40

Excellent video, I enjoy explanation.

Ответить
@foodsweets2728
@foodsweets2728 - 21.02.2021 06:21

You are too good but too fast, cant really follow.

Ответить
@terigopula
@terigopula - 17.01.2021 05:34

Explaining concepts with code is pure gold..! As Linus Torvalds says, "Talk is cheap show me the code".

Ответить
@copierofvideos2
@copierofvideos2 - 09.12.2020 07:10

Man this was great thanks! I always felt like c was a shitty language, but I can see that I just have to get more experience with it

Ответить
@hirenpatel6118
@hirenpatel6118 - 07.12.2020 00:47

Hi Jacob, confused as to why the value of client_socket is being copied to the heap? When the while loop starts again, shouldn't the new accept call return a different file descriptor than the last iteration? If we pass the file descriptor by value vs by reference we should be fine right?

Ответить
@lania4334
@lania4334 - 25.11.2020 17:19

Can you help me
How make this code when we have multiple clients just one client connect that server and the other clients wait for response's server until that client is completed

Ответить
@gaddeshamena6781
@gaddeshamena6781 - 25.11.2020 13:30

Well said sir😊😊

Ответить
@gaddeshamena6781
@gaddeshamena6781 - 25.11.2020 13:30

Sir I have aa doubt please can u help me can I send u in mail

Ответить
@meluobote7664
@meluobote7664 - 09.09.2020 11:07

very beautful code, what your IDE is? Is computer system Linux?

Ответить
@gamezone4470
@gamezone4470 - 24.06.2020 16:52

you are a fantastic, thank you very much ..... I have a question, I don't know if you can help me but I want to know how to create multiple processes that connect to the apache web server, establish a connection and keep it waiting, just wait for the server timeout , and when the connection is lost, the process should restart it.

In the end what I want is to see the simultaneous connections the web server can support, using a C language and fork () processes, the parent process will count how many processes achieve controls and many don't.

Ответить
@Marblewho
@Marblewho - 13.05.2020 06:58

What if the handle connection function takes more than one argument?

Ответить
@wildchild01
@wildchild01 - 20.04.2020 18:13

Hi Jacob, can you tell me more about the function "check" that you created? I want to use it in my code too. Thanks!

Ответить
@Teog1992
@Teog1992 - 30.03.2020 13:02

great videos ! Just wanted to ask , the first implementation of the threat , is essentially a producer/consumer model without a queue ?

Ответить
@ajidaniel8818
@ajidaniel8818 - 13.12.2019 18:05

If you are a teacher , i am sure you will produce a bunch of very good programmers.
Simple, Clear and Crisp , keep up the good work

Ответить
@marshalstewart7776
@marshalstewart7776 - 28.11.2019 09:52

Been really starting to get into computer science and these videos are always interesting and helpful!

Ответить
@andreykrasnov7851
@andreykrasnov7851 - 09.11.2019 23:15

Thank you for very good video, Jacob! Is it possible to find somewhere source code you use here?

Ответить
@cellularmitosis2
@cellularmitosis2 - 31.10.2019 09:31

Thank you so much for making these videos!

Ответить
@akshithbellare7568
@akshithbellare7568 - 29.10.2019 13:49

Hey I needed help with listening from two ports at the same time.What should I do for it?

Ответить
@LinucNerd
@LinucNerd - 08.10.2019 00:04

Please do a tutorial about Unicode, pls, I need this :c

Ответить
@simonpircher4551
@simonpircher4551 - 22.09.2019 01:17

thats the kind of videos i like. very interesting!

Ответить
@lordadamson
@lordadamson - 22.09.2019 00:44

Awesome stuff Jacob :D <3 Thank you.

Ответить
@SuperCape
@SuperCape - 20.09.2019 15:53

What's gonna happen if you pull a SlowLoris DoS attack on this server?

Ответить
@Huhnmonster
@Huhnmonster - 20.09.2019 12:23

Hello Jacob, thank you very much for your content. Would it be possible that you go over evented web servers some day? I would like to get your take on event loops and maybe even a small introduction to select or epoll/kqueue.

Ответить