Time and Date Server Program in UNIX

Time Server

#include<unistd.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
#include<sys/socket.h>
#include<stdio.h>
#include<time.h>
int main()
{
int sd,nsd,i,port=334114;
char sndmsg[100];
time_t t;
struct sockaddr_in ser, cli;
if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
{
printf("\n Error: socket creation");
return 0;
}
time(&t);
strcpy(sndmsg,ctime(&t));
printf("%s",sndmsg);
bzero((char*)&ser,sizeof(ser));
printf("\nport address %d",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sd,(struct sockaddr*)&ser,sizeof(ser))<0)
{
printf("\n Error:binding");
return 0;
}
i=sizeof(cli);
listen(sd,1);
printf("\n server module\n");
nsd=accept(sd,(sd,(struct sockaddr*)&cli),&i);
if(nsd<0)
{
printf("Error:client accepts the problem");
return 0;
}
printf("client Accepts \n");
send(nsd,sndmsg,100,0);
close(sd);
close(nsd);
return 0;
}

Time client

#include<unistd.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
#include<sys/socket.h>
#include<stdio.h>
#include<arpa/inet.h>
int main(int argc,char* argv[])
{
int sd,nsd,i,port=334114;
char rcvmsg[100];
struct sockaddr_in ser;
if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
{
printf("\n Error: socket creation");
return 0;
}
bzero((char*)&ser,sizeof(ser));
printf("\n port address is %d",port);
ser.sin_family=AF_INET;
ser.sin_port=htons(port);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(connect(sd,(struct sockaddr*)&ser,sizeof(ser))==-1)
{
printf("\n error:binding");
return 0;
}
printf("\n client module");
recv(sd,rcvmsg,100,0);
printf("\n\n%s \n",rcvmsg);
close(sd);
return 0;
}