= connect(client_fd, (struct sockaddr*)&serv_addr,
sizeof(serv_addr)))
< 0) {
printf("\nConnection Failed \n");
return -1;
}
send(client_fd, hello, strlen(hello), 0);
printf("Hello message sent\n");
valread = read(client_fd, buffer, 1024);
printf("%s\n", buffer);
// closing the connected socket
close(client_fd); return 0;} Compiling: gcc client.c -o client gcc server.c -o server Output: Client:Hello message sent Hello from server Server:Hello from client Hello message sent Next: Socket Programming in C/C++: Handling multiple clients on server without multi threading This article is contributed by Akshat Sinha. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. </code>
