Path: blob/master/03-tcp-ip-client-server/client.c
137 views
/*1Creating the TCP Client workflow in this program using C.23* Title : TCP client4* Name : Aditya Pratap Singh Rajput5* Subject : Network Protocols And Programming using C6Note : please consider the TYPOS in comments.7Thanks.8*/910// adding headers11#include <stdio.h>12#include <stdlib.h>13//for socket and related functions14#include <sys/types.h>15#include <sys/socket.h>16//for including structures which will store information needed17#include <netinet/in.h>18#include <unistd.h>19#define SIZE 10002021//main functions22int main()23{24int socketDescriptor = socket(AF_INET, SOCK_STREAM, 0);25// server address26struct sockaddr_in serverAddress;27serverAddress.sin_family = AF_INET;28serverAddress.sin_port = htons(9002);29serverAddress.sin_addr.s_addr = INADDR_ANY;3031// communicates with listen32connect(socketDescriptor, (struct sockaddr *)&serverAddress, sizeof(serverAddress));3334char serverResponse[SIZE];35recv(socketDescriptor, &serverResponse, sizeof(serverResponse), 0);36printf("Ther server sent the data : %s", serverResponse);3738//closing the socket39close(socketDescriptor);40return 0;41}424344