

The flow chart might look complicated but make sure you don’t lose your patience due to the following flow chart. The flow chart below shows the interaction between client and server. On client side, serv_addr.sin_port = htons(127.0.0.1) is declared in order to listen to the internal network. Inside red bracket, you will find 0.0.0.0:5000 and Socket-server, it means port 5000 is used and listen to any valid incoming address. Things that need to be initialized are listed as follows:Īt the beginning, a socket function needs to be declared to get the socket descriptor. Imagine a socket as a seaport that allows a ship to unload and gather shipping, whereas socket is the place where a computer gathers and puts data into the internet. It is because server is a kind of software. If you are experienced with constructing a server, you might find out that a server can be built on a home computer by installing a server OS. To be more precise, the server and client are two different processes with different jobs. It means what is happening on the top is there are two different software executed. The answer is the server and client both are software but not hardware. Why Both Server and Client on the Same Computer? Otherwise, do some checking on your development environment or try to run some simple code for instance hello world. If you see the message above, congratulations, you have success with your first step to networking programming. When you execute Socket-cli, I guess you will get the following result: It means, you need to open two terminals to run each of the outputs. Socket-server must be executed first, then execute Socket-client.out and never try to break Socket-server forever loop. Attention here, never mess up with the order of executing Socket-server.out and Socket-client. If((sockfd = socket(AF_INET, SOCK_STREAM, 0)) 0)Īfter debugging both source files, run Socket-server.out, then run Socket-client.


Memset(recvBuff, ' 0', sizeof(recvBuff))
