TCP Program Client and Server
TCP Program Client and Server
*/
#include<stdio.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<netdb.h>
#include<strings.h>
#include<unistd.h>
int main()
int clientsocket,port; //clientsocket is the socket descriptor , port is the port number
socklen_t len; //creating a variable to store the length of the server address
char message[50];
clientsocket=socket(AF_INET,SOCK_STREAM,0);//creating a socket
printf("\nMessage received.\t%s\n",message);
/*
s6d2@user-HP-280-G3-MT:~/Networking-Lab-S6/Socket-Programming/TCP$ ./client
s6d2@user-HP-280-G3-MT:~/Networking-Lab-S6/Socket-Programming/TCP$
*/
Server
/*
*/
#include<stdio.h>
#include<string.h>
#include<sys/socket.h>
#include<stdlib.h>
#include<netdb.h>
#include<unistd.h>
Int main()
Int serversocket,clientsocket,port; //clientsocket is the socket descriptor , port is the port number
Socklen_t len; //creating a variable to store the length of the server address
Char message[50]; //
Scanf(“%d”,&port);
Listen(serversocket,5); //listening to the socket, 5 is the number of clients that can connect to the
server
Printf(“\nhai:”);
/*
OUTPUT
S6d2@user-HP-280-G3-MT:~/Networking-Lab-S6/Socket-Programming/TCP$ ./server
Hai:
S6d2@user-HP-280-G3-MT:~/Networking-Lab-S6/Socket-Programming/TCP$ ^C
*/