Sunteți pe pagina 1din 5

The TCP client program sends two strings to the TCP server program to

concatenate these two Strings -The TCP server program sends the
concatenated string to the client.

Ans.
Client.c

#include<arpa/inet.h>

#include<netinet/in.h>

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<sys/socket.h>

#include<unistd.h>

#define PORT 8090

int main()

Struct sockaddr_in address;

Int sock =0,valread;

Char str1[100],str2[100],str[200];

Printf(“\n input the string:”);

Scanf(“%[^\n]s”,str);

Char buffer[1024]={0};

If((sock=socket(AF_STREAM,0))<0)

If((sock=socket(AF_STREAM,0))<0)

Printf("\n Socket creation errror \n");

return -1;

memset(&serv_addr,'0', sizeof(serv_addr));

serv_addr.sin_family=AF_INET;
serv_addr.sin_port=htons(PORT);

if(inet_pton(AF_INET,"127.0.01,&serv_add.sin_addr")<=0)

Printf("\nAddress not supported\n");

return-1;

if (connect(sock,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)

Printf("\nconnecton is failled\n")

return-1;

int l=strlen(str1)+strlen(str2);

Printf("ENTER the string 1")

Gets(str1)

Printf("ENTER the string 2")

Gets(str2)

send(sock,str1,sizeof(str1),0);

send(sock,str2,sizeof(str2,0);

//reaad string sent by the sender

varread=read(sock,str,1);

Printf("%s\n",str);

return 0;

Server.c

#include<arpa/inet.h>

#include<netinet/in.h>

#include<stdio.h>

#include<stdlib.h>
#include<string.h>

#include<sys/socket.h>

#include<unistd.h>

#define PORT 8090

int main()

int server_fd,new_socket,valread;

struct sockaddr_in address;

char str[100];

int addrlen=sizeof(address);

char buffer[1024]={0}

char st1[100],st2[100];

If((server_fd=socket(AF_INET,SOCK_STREAM,0))==0)

perror("socket failed");

exit(EXIT_FAILURE);

address.sin_family=AF_INET;

address.sin_addr.s_addr=INADDR_ANY;

address.sin_port=htons(PORT)

if(bind(server_fd=socket(struct sockadd*)&address,sizeof(address<0))

perror("bind failed");

exit(EXIT_FAILURE);

if (listen(server_fd,3)<0)

perror("listen");

exit(EXIT_FAILURE);

}
if ((new_soket=accept(server_fd,(struct sockaddr*)&address,(socklen_t
*)&addrlen))<0)

perror("ACCEPT");

exit(EXIT_FAILURE);

//READ STRING SEND BY THE CLENT

R1=read(new_socket,str1,sizeof(str1));

R2=read(new_socket,str2,sizeof(str2));

strcpy(str1,str2)

//send and reversed string to client

//by send system call

send(new_socket,str1,sizeof(str1),0)

printf("\n Modefied string sent to clent\n")

return 0;

Q2.a) Run the following Linux commands on your machine and show
the output()
Df-h,Du,Ping,More,Tail-f

1. Df-h

pass the h option to see the output in human readable format. You will device
size in gigabytes or terabytes or megabytes
output
filesystem size Used Avail use%
mounted option

/dev/cciss/c0d0p2 75G 23G 49G 32%


/

/dev/cciss/c0d0p5 75G 23G 49G 95%


/home

/dev/cciss/c0d0p3 75G 23G 49G 91%


/data

/dev/cciss/c0d0p1 75G 23G 49G 8%


/boot

tmpfs 252M 0 252M 0%


/dev/shm

2. Du

Du-h/home/xavi/test

output
44k /home/xavi/test/data

2.0M /home/xavi/test/data/system design

44k /home/xavi/test/data/table/sample_table

32k /home/xavi/test/data/table

98M /home/xavi/test/data

3. Ping

Ping google.com

Ping google.com(74.125.200.102)56(84)bytes of data

64bytes from
plus.google.com(74.125.200.102):icmp_req=1ttl=128time=172ms

S-ar putea să vă placă și