Assignment BCSL 56
Assignment BCSL 56
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>
int main()
Char str1[100],str2[100],str[200];
Scanf(“%[^\n]s”,str);
Char buffer[1024]={0};
If((sock=socket(AF_STREAM,0))<0)
If((sock=socket(AF_STREAM,0))<0)
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)
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);
Gets(str1)
Gets(str2)
send(sock,str1,sizeof(str1),0);
send(sock,str2,sizeof(str2,0);
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>
int main()
int server_fd,new_socket,valread;
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);
R1=read(new_socket,str1,sizeof(str1));
R2=read(new_socket,str2,sizeof(str2));
strcpy(str1,str2)
send(new_socket,str1,sizeof(str1),0)
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
2. Du
Du-h/home/xavi/test
output
44k /home/xavi/test/data
44k /home/xavi/test/data/table/sample_table
32k /home/xavi/test/data/table
98M /home/xavi/test/data
3. Ping
Ping google.com
64bytes from
plus.google.com(74.125.200.102):icmp_req=1ttl=128time=172ms