Chat Program in UNIX system

//CLIENT:

#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netdb.h>
int main()
{
int sd,cd,b,clen;
char fname[50],sip[15],flname[50];
struct sockaddr_in caddr,saddr;
char str[10];
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd!=-1)
printf("\nSocket is created\n");
else
printf("\nSocket is not created");
saddr.sin_family=AF_INET;
saddr.sin_addr.s_addr=htonl(INADDR_ANY);
saddr.sin_port=htons(9040);
b=bind(sd,(struct sockaddr*)&saddr,sizeof(saddr));
if(b>=0)
printf("Binded to client");
else
printf("Not binded");
listen(sd,3);
cd=accept(sd,(struct sockaddr*)&caddr,&clen);
for(;;)
{
recv(cd,fname,sizeof(fname),0);
printf("\n The received data is:%s ",fname);
printf("\n The data has been transferred");
printf("Enter the name:");
scanf("%s",flname);
send(cd,flname,sizeof(flname),0);
}
close(sd);
close(cd);
return 0;
}

//SERVER:

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<netdb.h>
#include<sys/socket.h>
int main()
{
int sd,c,s;
char fname[50],sip[15],flname[50];
struct sockaddr_in caddr;
struct hostent *he;
printf("\nEnter the server IP address:");
scanf("%s",sip);
he=gethostbyname(sip);
sd=socket(AF_INET,SOCK_STREAM,0);
if(sd!=-1)
printf("\nSocket is created");
else
printf("\nSocket is not created");
caddr.sin_family=AF_INET;
caddr.sin_addr=*((struct in_addr*)he->h_addr);
caddr.sin_port=htons(9040);
c=connect(sd,(struct sockaddr*)&caddr,sizeof(caddr));
if(c=0)
printf("\nConnected to server");
else
printf("\nNot connected");
for(;;)
{
printf("\nEnter the name:");
scanf("%s",fname);
send(sd,fname,sizeof(fname),0);
printf("the received data is:");
recv(sd,flname,sizeof(flname),0);
printf("%s",flname);
}
close(sd);
return 0;
}
OUTPUT:
//server:
[mca31@mcaserver ~]$ cc serchat.c
[mca31@mcaserver ~]$ ./a.out
Socket Create
Connection Accepted
Enter the data to be send type exit for stop:
Connection Accepted
Received from client : HAI
IAM_FINE
Received from client : THANKS
//client:
[mca31@mcaserver ~]$ cc clichat.c
[mca31@mcaserver ~]$ ./a.out
Enter the data to be send type exit for stop: HAI
Received from server: IAM_FINE
THANKS