Weather Server written in C
Here are the steps for using the server side socket API in C
-
socket() "Socket() creates a socket that returns an integer which is the file descriptor of the socket"
-
bind() "Bind() binds the socket to a specific port and returns an integer describing the error state of the command"
-
listen() "listen() makes the server listen at a specified port, until a client sends a request to connect"
-
accept() "accept() is after the client has connected to the server, and that signifies the two computers are ready communicate"
-
recv() "recv() is fairly self-explainatory, and receives data from the client"
-
send() "send() is also self-explainatory and sends data to a client, and they both return a -1 if an error arises" ...
-
close() "close() closes the connection, usually listen is called after close()"
We are calling each socket API function with the preprocessor macro check() which takes in a function and parameters and applies the function to the supplied parameters. It automatically checks for errors and if errors arise, it prints to stderr.