Question: I need Linux user for run 2 C program in terminal. Because i cannot use Linux because of my computer problem. Run 2 c files

I need Linux user for run 2 C program in terminal. Because i cannot use Linux because of my computer problem.

Run 2 c files in terminal, it should complete the screenshot.

First code :

#include

#include

#include

#include

#include

#include

#include

#define SER_PORT 1200

int main()

{

int a,sersock,newsock,n;

char str[25],str2[25];

struct sockaddr_in seraddr;

struct sockaddr_in cliinfo;

socklen_t csize=sizeof(cliinfo);

seraddr.sin_family=AF_INET;

seraddr.sin_port=htons(SER_PORT);

seraddr.sin_addr.s_addr=htonl(INADDR_ANY);

if((sersock=socket(AF_INET,SOCK_STREAM,0))<0)

{

error(" socket");

exit(0);

}

if(bind(sersock,(struct sockaddr *)&seraddr,sizeof(seraddr))<0)

{

error(" BIND");

exit(0);

}

if(listen(sersock,1)<0)

{

error(" LISTEN");

}

if((newsock=accept(sersock,(struct sockaddr *)&cliinfo,&csize))<0)

{

error(" ACCEPT");

exit(0);

}

else

printf(" now connected to %s ",inet_ntoa(cliinfo.sin_addr));

read(newsock,str,sizeof(str));

do

{

printf(" client msg:%s",str);

printf(" server msg:");

scanf("%s",str2);

write(newsock,str2,sizeof(str2));

listen(newsock,1);

read(newsock,str,sizeof(str));

n=strcmp(str,"BYE");

a=strcmp(str2,"BYE");

}

while(n!=0||a!=0);

close(newsock);

close(sersock);

return 0;

}

Second Code :

#include

#include

#include

#include

#include

#include

#define SER_PORT 1200

int main(int count,char*arg[])

{

int a,clisock;

char str[20],str2[20];

struct sockaddr_in cliaddr;

cliaddr.sin_port=htons(SER_PORT);

cliaddr.sin_family=AF_INET;

cliaddr.sin_addr.s_addr=inet_addr(arg[1]);

clisock=socket(AF_INET,SOCK_STREAM,0);

if(clisock<0)

{

perror(" SOCKET");

exit(0);

}

if(connect(clisock,(struct sockaddr*)&cliaddr,sizeof(cliaddr))<0)

{

perror(" CONNECT");

exit(0);

}

printf(" client connected to %s",arg[1]);

printf(" CLIENT");

scanf("%s",&str);

if(write(clisock,str,sizeof(str))<0)

{

printf(" data could not be sent");

}

do

{

listen(clisock,1);

read(clisock,str2,sizeof(str2));

printf(" server msg:%s",str2);

printf(" client msg:");

scanf("%s",&str);

a=strcmp(str2,"BYE");

write(clisock,str2,sizeof(str2));

}

while(a!=0);

close(clisock);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!