Socket Programming Tutorial In C For Beginners | Part 1 | Eduonix
Why Stack Overflow recommends it
Stack Overflow users link it as the tutorial they followed when their C socket code failed to compile, close properly, or work across two machines.
Recommended by 2 people across 2 different months, 2019 to 2023.
What it is
A 40-minute beginner tutorial from Eduonix on socket programming in C. It covers what sockets are, the client socket workflow and the server socket workflow, with a simple TCP client and server written along the way.
What people said
Recommends RushiSrinivas.K · 2020-08 · Stack Overflow · on “How to close sockets in C (GCC on Linux)”
I'm completely new to C. And am following this yt tutorial [this video] on sockets. However he's using the close(sock) function. There's 2 problems: There's no variable called sock . The socket is called something else. I can't find the close function. The compiler is saying that the function doesn't exist Can you please explain. This question might seem a little too dumb. Here's the Client code: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> int main() { // Create a socket int network_socket; network_socket = socket(AF_INET, SOCK_STREAM, 0); // Address for the socket struct sockaddr_in server_address; server_address.sin_family = AF_I
Recommends krystof · 2020-11 · Stack Overflow · on “Connection between two computers using sockets in C. (TCP)”
I have been following this [this video] tutorial to learn something about socket programming in C. Everythink is working just fine, but it only works on one PC. I would like to know how to host server on one PC (I will use rpi4 in future) and connect to the server with client on another PC. This is code for server, when client connect to server, it sends "You have reached the server" message to client. #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> int main(int argc, char const *argv[]) { char server_message[256] = "You have reached the server"; int server_socket = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in server_address; se
Cites B-S-1 · 2019-04 · Stack Overflow · on “How to fix "format specifies type 'char *' but the argument has type 'char **'" error”
I am setting up a Client Socket system, and the code all will make but the part referencing server_response. I am following a tutorial, but nobody else in the comments seemed to have this issue. What is causing this error and how do I fix it? I was following this tutorial about halfway through I encountered this bug, and the issue is not addressed in the comments or in the video. [this video] int network_socket; network_socket = socket(AF_INET, SOCK_STREAM, 0); //Address structure that holds access info for socket struct sockaddr_in server_address; server_address.sin_family = AF_INET; //specifies family or type of address, in this case an internet based one server_address.sin_port = htons(13001);
Cites Tomas barta · 2023-07 · Stack Overflow · on “TCP server in c”
I am trying to make tcp server and client so that message i send from server to client will be printed to stdout i have macbook and linux. I want to have server on macbook and client on linux. output of ip addr on linux : inet 10.0.1.175/24 brd 10.0.1.255 output of ifconfig on mac is: inet 10.0.1.165 on both machines i am compiling with command: gcc tcp_server_01.c -o server gcc tcp_client_01.c -o client macbook is m1 linux is orange pi 5 with armbian code for tcp_server_01.c: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <unistd.h> #include <arpa/inet.h> int main () { char server_message[250] = "message was recived for