Lab3 CN1
Lab3 CN1
Lab3 CN1
CLIENT
STEP 1: Start the program.
STEP 2: Declare the variables and structure.
STEP 3: Socket us created and connect function is executed.
STEP 4: If the connection is successful then server sends the message.
STEP 5: The date and time is printed at the client side.
STEP 6: Stop the program.
CODE:
server.c :
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
char sendBuff[1025];
time_t ticks;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(5000);
listen(listenfd, 10);
while(1)
ticks = time(NULL);
close(connfd);
sleep(1);
}
client.c :
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
int sockfd = 0, n = 0;
char recvBuff[1024];
if(argc != 2)
return 1;
memset(recvBuff, '0',sizeof(recvBuff));
return 1;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(5000);
return 1;
return 1;
recvBuff[n] = 0;
if(n < 0)
return 0;
}
Output:
CSBS- R1
***********************************************************************************************