![logic world socket logic world socket](https://live.staticflickr.com/2674/3848143816_cde4dc2851.jpg)
NewSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size) *- Accept call creates a new socket for the incoming connection -*/ *- Listen on the socket, with 5 max connection requests queued -*/ *- Bind the address struct to the socket -*/īind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) Memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero) * Set all bits of the padding field to 0 */ * Set port number, using htons function to use proper byte order */ *- Configure settings of the server address struct -*/ WelcomeSocket = socket(PF_INET, SOCK_STREAM, 0)
![logic world socket logic world socket](https://live.staticflickr.com/6150/5953114249_3bec1b3bcd_b.jpg)
* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */ Third, if you want more details about the functions or their arguments please check the man page of each one.įinally, to test the code you just need to run the server on a terminal and then run the client on a different terminal (or run the server as a background process and then run the client on the same terminal). You should implement those checks if you are going to use the code for a real project. Second, I am not doing error checking on most function calls.
#Logic world socket portable#
If you want your code to be IPV4-IPV6 agnostic, IP agnostic and portable to different plataforms you can use the getaddrinfo() function, as explained in this tutorial. Keep in mind that I am configuring the settings manually. Basically the client connects to the server, the server sends the message “Hello World”, and the client prints the received message. Below you’ll find an example of a very simple client-server program in C.