there is a buffer overflow when using scanf("%s", buffer); because scanf("%s") doesnt check how many bytes are entered. may result in a DoS or remote code execution.
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.
Can you please elaborate more on what does code do at line 56, fork creates a new process and we are closing the child but receiving the data inside child only, how is this working? there is no code to execute for parent process
5 років тому+2
Nice Video, Can you limit the connection to 100 client in same time only? Can you do this example please?
Hello, how would I approach making the server ask the client for a name so that "printf" would print the client's name that was received instead of printing "client:"
Very interesting video. Can you please tell me how to make the server wait for a user message and then send it to the client (chat), and not responding with the same message. Thank you.
Concurrent Simultaneous Action Hi i am having 2 laptops with different user names but same OS & settings, files. If i open control panel and change some settings say mouse sensitivity in laptop 1, the same should happen live/real time in laptop 2 and vice versa. Is is possible?
When you fork a process you clone the process and store its id in pid. How does the program knows which process is it working on? Simple! If pid == 0 it means you are in the child process. If you are in the parent process, then the pid variable would have another value, and thats because the fork() returns twice. So... going back to your original question... why close the socket in child process? Well you might have realized that there are two sockets... or socket decriptors. There is sockfd (the socket that the server uses to listen for new clients) and newSocket (the socket the server send() and recv() directly to and from the connected client). So... the forked process is used for writing and reading from the newSocket, not for listening, that work belongs to the parent process, so whatever you execute inside if(pid == 0){} block would only happen inside the child process, not in the parent. The sockfd would be closed in the child process and not in the parent... so the parent would continue to listen for connections and the child would use the newSocket returned by the accept() to send and recv messages. Why forking the process? Well, multitasking of course! Threads are complicated and forking tends to be a much better idea. You might have realized he is sending and receiving messages at the same time, thats thanks to fork(). Sorry I made it too long. I hope I was of help!
We can avoid garbage value which display in server by using this code int rv=recv(newsockfd,buffer,1024,0); buffer[rv]='\0'; printf("%s",buffer); then it will not display garbage value. because when it is transferred in transfer one by one character. like as character array. then we make it string by using NULL character. '\0' . Any Networking program visit google and search javatech 123
@@coverscollection8775 @Covers Collection you just add two lines in while loop in server program. while(1){ int size=recv(newSocket, buffer, 1024, 0); buffer[size]='\0'; if(strcmp(buffer, "exit") == 0){
The two computers must be connected to each other like in a LAN. Then use the server computer ip address instead of localhost. Then on client computer use the server ip address for connecting to server.
I had the same problem. You can do it, by setting in client code server's IP address. Moreover you have to set one line like this: serverAddr.sin_addr.s_addr = INADDR_ANY. Then you can connect many clients from different machines, which working LAN. If you want connect with Virtualbox machine, you should set network card as bridged.
System call fork() is used to create processes. It takes no arguments and returns a process ID. The purpose of fork() is to create a new process, which becomes the child process of the caller. After a new child process is created, both processes will execute the next instruction following the fork() system call. You can specify the number of clients in listen method. If you wants to limit upto N clients, then specify N in listen method.listen(sockfd, N)
@@IdiotDeveloper But that indicates how many client can wait. I'm currently using a counter and accept only if less than 3 client is connected. But sometime it doesn't work. As it's not always able to count the disconnected clients.
I agree with you. This tutorial was recorded when I was new to content creation. I just somehow want to implement the program and don't think from the perspective for new person.
When you fork a process you clone the process and store its id in pid. How does the program knows which process is it working on? Simple! If pid == 0 it means you are in the child process. If you are in the parent process, then the pid variable would have another value, and thats because the fork() returns twice. So... going back to your original question... why close the socket in child process? Well you might have realized that there are two sockets... or socket decriptors. There is sockfd (the socket that the server uses to listen for new clients) and newSocket (the socket the server send() and recv() directly to and from the connected client). So... the forked process is used for writing and reading from the newSocket, not for listening, that work belongs to the parent process, so whatever you execute inside if(pid == 0){} block would only happen inside the child process, not in the parent. The sockfd would be closed in the child process and not in the parent... so the parent would continue to listen for connections and the child would use the newSocket returned by the accept() to send and recv messages. Why forking the process? Well, multitasking of course! Threads are complicated and forking tends to be a much better idea. You might have realized he is sending and receiving messages at the same time, thats thanks to fork(). Sorry I made it too long. I hope I was of help!
@@brianfiszman3179 I don't understand. How can the client's socket inside the if(pid==0){} block be the same as the one that was accepted by the parent while the server's socket is different?
this video is good, it's like milky way
Thanks
@@IdiotDevelopertumhara bohot bohot shukriya tumhare wajah se me exam pass hua🥺
I love you. You saved me on a big assignment for handling multiple clients with sockets for my last class to graduate. Thank you.
I am stucked in the same situation... Maybe u can help
I tried the same program I am not able to do can u please help me
Thank you!! For helping many people through your explanation
Hi sir , the way you speak is so funny by the way informative video thanks
there is a buffer overflow when using scanf("%s", buffer); because scanf("%s") doesnt check how many bytes are entered. may result in a DoS or remote code execution.
Thanks for the information.
@@IdiotDeveloper the fix is scanf with "1024s" as format specifier to tell scanf that only read 1024 bytes no more than that
@@X3eRo0 hi can you help me fixing the garbage value in the server output? I tried your method but its still
Sorry, why did you close the sockfd socket after fork call?
Did you find an answer?
Thank you so much . You solve my problem .
Thanks, helped to understand sockets in Linux
Great video you're very clear and concise, helped a lot!!
Thanks bro. Do share and subscribe
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.
I don't understand why the server's socket is closed while it is still needed. Can someone explain why is that?
This is good one. Keep doing god work !
Can you please elaborate more on what does code do at line 56, fork creates a new process and we are closing the child but receiving the data inside child only, how is this working? there is no code to execute for parent process
Nice Video, Can you limit the connection to 100 client in same time only? Can you do this example please?
Hello, how would I approach making the server ask the client for a name so that "printf" would print the client's name that was received instead of printing "client:"
is it possible for the cilient to chat with each other? if yes, how?
Super cool thanks could you make an explanatory video on how to implement a multiplayer mode with sockets in a game c ?
Can you explain it with little more details.
@@IdiotDeveloper I was thinking of a basic shooting game from scratch or with a library in which we could code a LAN with sockets or something like it
Can we also read the data from first client to another client in socket ?
what is the difference of sockfd and newSocket and why do I need to initialize the struct sock_addr twice?
thank you so much you were very helpful
why there is close(sockfd) in the server program after fork??
I have the same question
Did any of you find the answer?
Very interesting video.
Can you please tell me how to make the server wait for a user message and then send it to the client (chat), and not responding with the same message.
Thank you.
thank you it was really helpfull
Thank you very much
This lesson is very important
God bless you
We will not deny you.
Welcome. Do Share and Subscribe.
Concurrent Simultaneous Action
Hi i am having 2 laptops with different user names but same OS & settings, files.
If i open control panel and change some settings say mouse sensitivity in laptop 1, the same should happen live/real time in laptop 2 and vice versa.
Is is possible?
Why are u closing the socket in child process --line 57 in tcpServer...plz explain
When you fork a process you clone the process and store its id in pid. How does the program knows which process is it working on?
Simple! If pid == 0 it means you are in the child process. If you are in the parent process, then the pid variable would have another value, and thats because the fork() returns twice.
So... going back to your original question... why close the socket in child process? Well you might have realized that there are two sockets... or socket decriptors. There is sockfd (the socket that the server uses to listen for new clients) and newSocket (the socket the server send() and recv() directly to and from the connected client).
So... the forked process is used for writing and reading from the newSocket, not for listening, that work belongs to the parent process, so whatever you execute inside if(pid == 0){} block would only happen inside the child process, not in the parent. The sockfd would be closed in the child process and not in the parent... so the parent would continue to listen for connections and the child would use the newSocket returned by the accept() to send and recv messages.
Why forking the process? Well, multitasking of course! Threads are complicated and forking tends to be a much better idea. You might have realized he is sending and receiving messages at the same time, thats thanks to fork().
Sorry I made it too long. I hope I was of help!
@@brianfiszman3179 thanks it was really helpful
You said we need to make some changes to make it chat application so can I get to know what are those?!
Thank you, your video was really helpful!
Your Welcome. Do share and subscribe.
We can avoid garbage value which display in server by using this code
int rv=recv(newsockfd,buffer,1024,0);
buffer[rv]='\0';
printf("%s",buffer);
then it will not display garbage value. because when it is transferred in transfer one by one character. like as character array. then we make it string by using NULL character. '\0' . Any Networking program visit google and search javatech 123
hi can you help me fixing the garbage value in the server output?
@@coverscollection8775 @Covers Collection you just add two lines in while loop in server program.
while(1){
int size=recv(newSocket, buffer, 1024, 0);
buffer[size]='\0';
if(strcmp(buffer, "exit") == 0){
17:40 main thing
How to connect client from different system.
Where I have to change in client and server program
The two computers must be connected to each other like in a LAN. Then use the server computer ip address instead of localhost. Then on client computer use the server ip address for connecting to server.
Thanks , very helpful.
But how we can limit the number of clients that are connected to the server, for example 10 clients ?????
just specify the number of clients you wants in the listen commands.
listen(sockfd,10);
Can we use server class in c language and client class in java language and establish connection between them ?
I think both the program should work perfectly fine.
@@IdiotDeveloper can u please provide same program ?
Is this type of connection asynchronous?
Hi how can I reach out to u I need help in this
same.... I am doing a project and need his help
@@Xp-Sam did u figured it out how to do
@@ishwaryaj9789 nope...
@@Xp-Sam did u follow the way he did and u got something?
Excuse me How do I connect 2 different machines?
Please help me
I had the same problem. You can do it, by setting in client code server's IP address. Moreover you have to set one line like this: serverAddr.sin_addr.s_addr = INADDR_ANY. Then you can connect many clients from different machines, which working LAN. If you want connect with Virtualbox machine, you should set network card as bridged.
thank you so much
What does "childpid = fork()" means?
What is it for?
How to limit the number of client?
System call fork() is used to create processes. It takes no arguments and returns a process ID. The purpose of fork() is to create a new process, which becomes the child process of the caller. After a new child process is created, both processes will execute the next instruction following the fork() system call.
You can specify the number of clients in listen method.
If you wants to limit upto N clients, then specify N in listen method.listen(sockfd, N)
@@IdiotDeveloper But that indicates how many client can wait. I'm currently using a counter and accept only if less than 3 client is connected. But sometime it doesn't work. As it's not always able to count the disconnected clients.
how would you make this program to send a message from Client A, go though server and end up in client B?
Then we need to make the server a router, to route message from client A to B and vice-versa.
did you find the answer??
thank you.it is really nice
+bhawna kamra you welcome. Please share and subscribe
Sorry Sir
but what thing you explained ?
you were just speaking what you were writing......
anyone can correct me if I'm wrong
I agree with you. This tutorial was recorded when I was new to content creation. I just somehow want to implement the program and don't think from the perspective for new person.
@@IdiotDeveloper ok sir
How to implement concurrent server without using fork system call. Please explain in briefly.
How to share files through this?
Thank you!
Make sure to share and subscribe
What if we had 5 clients from fork?
I am not sure about that, but I think the server should work fine for 5 clients.
How do you shutdown/exit the server without CTRL+C?
do you have the fix?
thank you
Welcome. Do Share and Subscribe.
i love like this program
Thanks.
Give me
the file please
Download it from GITHUB
github.com/nikhilroxtomar/Multiple-Client-Server-Program-in-C-using-fork
Please make a video to explain it
How to create header file sys/socket.h
Please tell me how to do
multi Cline one server plllllllllllease
I think this program is a multi-client server.
thanks for code
+Aditya Kumar Your welcome. Do subscribe and share.
please Give me
the file Cline and server.c or cc
Download it from GITHUB
github.com/nikhilroxtomar/Multiple-Client-Server-Program-in-C-using-fork
#burlão
Why are u closing the socket in child process --line 57 in tcpServer...plz explain
When you fork a process you clone the process and store its id in pid. How does the program knows which process is it working on?
Simple! If pid == 0 it means you are in the child process. If you are in the parent process, then the pid variable would have another value, and thats because the fork() returns twice.
So... going back to your original question... why close the socket in child process? Well you might have realized that there are two sockets... or socket decriptors. There is sockfd (the socket that the server uses to listen for new clients) and newSocket (the socket the server send() and recv() directly to and from the connected client).
So... the forked process is used for writing and reading from the newSocket, not for listening, that work belongs to the parent process, so whatever you execute inside if(pid == 0){} block would only happen inside the child process, not in the parent. The sockfd would be closed in the child process and not in the parent... so the parent would continue to listen for connections and the child would use the newSocket returned by the accept() to send and recv messages.
Why forking the process? Well, multitasking of course! Threads are complicated and forking tends to be a much better idea. You might have realized he is sending and receiving messages at the same time, thats thanks to fork().
Sorry I made it too long. I hope I was of help!
@@brianfiszman3179 really very good thanks man
@@brianfiszman3179 I don't understand. How can the client's socket inside the if(pid==0){} block be the same as the one that was accepted by the parent while the server's socket is different?
@@brianfiszman3179 Thanks very helpful and clear