**********************************SERVER***************************************
#include <sys/types.h>
#include <sys/socket.h>
#include<stdio.h>
#include <unistd.h>
#include<netinet/in.h>
#include<string.h>
#define SERV_TCP_PORT 5035
int main(int argc,char**argv)
{
int sockfd,clientfd,len;
char tubelight[100];
struct sockaddr_in server1,client1;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
{
printf("Socket Creation Fail\n");
}
else
printf("Socet 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");
len=sizeof(client1);
clientfd=accept(sockfd,(struct sockaddr*)&client1,&len);
printf("Accepted......\n");
while(1)
{
read(clientfd,tubelight,100);
printf("TUBELIGHT=%s",tubelight);
bzero(tubelight,sizeof(tubelight));
printf("SUMIT:-");
fgets(tubelight,100,stdin);
write(clientfd,tubelight,100);
}
close(sockfd);
}
*****************************************CLIENT**********************************
#include<stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include<string.h>
#define SERV_TCP_PORT 5035
int main(int argc,char **argv)
{
int sockfd;
char tubelight[100];
struct sockaddr_in server1;
struct hostent *server;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
printf("Error in Creation.....\n");
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));
while(1)
{
//bzero(tubelight,sizeof(tubelight));
printf("TUBELIGHT:-");
fgets(tubelight,100,stdin);
write(sockfd,tubelight,100);
bzero(tubelight,sizeof(tubelight));
read(sockfd,tubelight,100);
printf("server=%s",tubelight);
}
close(sockfd);
}
#include <sys/types.h>
#include <sys/socket.h>
#include<stdio.h>
#include <unistd.h>
#include<netinet/in.h>
#include<string.h>
#define SERV_TCP_PORT 5035
int main(int argc,char**argv)
{
int sockfd,clientfd,len;
char tubelight[100];
struct sockaddr_in server1,client1;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
{
printf("Socket Creation Fail\n");
}
else
printf("Socet 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");
len=sizeof(client1);
clientfd=accept(sockfd,(struct sockaddr*)&client1,&len);
printf("Accepted......\n");
while(1)
{
read(clientfd,tubelight,100);
printf("TUBELIGHT=%s",tubelight);
bzero(tubelight,sizeof(tubelight));
printf("SUMIT:-");
fgets(tubelight,100,stdin);
write(clientfd,tubelight,100);
}
close(sockfd);
}
*****************************************CLIENT**********************************
#include<stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include<string.h>
#define SERV_TCP_PORT 5035
int main(int argc,char **argv)
{
int sockfd;
char tubelight[100];
struct sockaddr_in server1;
struct hostent *server;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
printf("Error in Creation.....\n");
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));
while(1)
{
//bzero(tubelight,sizeof(tubelight));
printf("TUBELIGHT:-");
fgets(tubelight,100,stdin);
write(sockfd,tubelight,100);
bzero(tubelight,sizeof(tubelight));
read(sockfd,tubelight,100);
printf("server=%s",tubelight);
}
close(sockfd);
}
No comments:
Post a Comment