***************************************SERVER*******************************
#include<stdio.h>
#include<netinet/in.h>
#include<netdb.h>
#define SERV_TCP_PORT 5035
int main(int argc,char**argv)
{
int clen,sockfd,clientfd;
char buffer[4096];
struct sockaddr_in server1,client1;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
printf("Socket Creation Failed....\n");
else
printf("Socket Created.....\n");
server1.sin_family=AF_INET;
server1.sin_port=htons(SERV_TCP_PORT);
server1.sin_addr.s_addr=INADDR_ANY;
bind(sockfd,(struct sockaddr *)&server1,sizeof(server1));
printf("Binding......\n");
listen(sockfd,5);
printf("Listening.....\n");
clen=sizeof(client1);
clientfd=accept(sockfd,(struct sockaddr *)&client1,&clen);
printf("Accepted....\n");
read(clientfd,buffer,4096);
printf("CLIENT:-%s",buffer);
write(clientfd,buffer,4096);
close(sockfd);
}
******************************************CLIENT********************************
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#define SERV_TCP_PORT 5035
int main(int argc,char**argv)
{
int sockfd;
struct sockaddr_in server1;
struct hostent *server;
char buffer[4096];
sockfd=socket(AF_INET,SOCK_STREAM,0);
server1.sin_family=AF_INET;
server1.sin_port=htons(SERV_TCP_PORT);
server1.sin_addr.s_addr=inet_addr("127.0.0.1");;
connect(sockfd,(struct sockaddr*)&server1,sizeof(server1));
printf("enter Message..");
fgets(buffer,4096,stdin);
write(sockfd,buffer,4096);
printf("%s",buffer);
close(sockfd);
return 0;
}
#include<stdio.h>
#include<netinet/in.h>
#include<netdb.h>
#define SERV_TCP_PORT 5035
int main(int argc,char**argv)
{
int clen,sockfd,clientfd;
char buffer[4096];
struct sockaddr_in server1,client1;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
printf("Socket Creation Failed....\n");
else
printf("Socket Created.....\n");
server1.sin_family=AF_INET;
server1.sin_port=htons(SERV_TCP_PORT);
server1.sin_addr.s_addr=INADDR_ANY;
bind(sockfd,(struct sockaddr *)&server1,sizeof(server1));
printf("Binding......\n");
listen(sockfd,5);
printf("Listening.....\n");
clen=sizeof(client1);
clientfd=accept(sockfd,(struct sockaddr *)&client1,&clen);
printf("Accepted....\n");
read(clientfd,buffer,4096);
printf("CLIENT:-%s",buffer);
write(clientfd,buffer,4096);
close(sockfd);
}
******************************************CLIENT********************************
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#define SERV_TCP_PORT 5035
int main(int argc,char**argv)
{
int sockfd;
struct sockaddr_in server1;
struct hostent *server;
char buffer[4096];
sockfd=socket(AF_INET,SOCK_STREAM,0);
server1.sin_family=AF_INET;
server1.sin_port=htons(SERV_TCP_PORT);
server1.sin_addr.s_addr=inet_addr("127.0.0.1");;
connect(sockfd,(struct sockaddr*)&server1,sizeof(server1));
printf("enter Message..");
fgets(buffer,4096,stdin);
write(sockfd,buffer,4096);
printf("%s",buffer);
close(sockfd);
return 0;
}
No comments:
Post a Comment