Path: blob/master/05-day-time-server-tcp-ip/server.c
137 views
/**1* Title : Day-Time server2* Name : Aditya Pratap Singh Rajput3* Subject : Network Protocols And Programming using C4*5* */67//program for date time server8#include<stdio.h>9#include<stdlib.h>10#include<sys/types.h>11#include<sys/socket.h>12#include<netinet/in.h>13#include<unistd.h>14#include<time.h>1516//port value and the max size for buffer17#define PORT 9002 //the port users will be connecting to18#define BACKLOG 10 //how many pending connections queue will hold1920int main(){21//*******************Time Setup***********************22time_t currentTime ;23time(¤tTime);24//****************************************************2526int countClient = 0;2728int socket_descriptor = socket(AF_INET, SOCK_STREAM, 0);2930struct sockaddr_in serverAddress;31serverAddress.sin_family = AF_INET;32serverAddress.sin_addr.s_addr=INADDR_ANY;33serverAddress.sin_port=htons(PORT);3435//binding address36bind(socket_descriptor,(struct sockaddr*)&serverAddress,sizeof(serverAddress));3738//listening to the queue39listen(socket_descriptor,BACKLOG);4041printf("\nServer Started ...");4243while(1){44countClient++;45printf("\n");4647int client_socket = accept(socket_descriptor, NULL, NULL);48// char *string = asctime(timeinfo);4950printf("\nClient %d has requested for time at %s", countClient, ctime(¤tTime));5152//sending time to the client side53// ctime(&time_from_pc)54send(client_socket,ctime(¤tTime), 30, 0);5556}57return 0;58}596061