Phase I Essay

1244 WordsFeb 9, 20145 Pages
ECHO CLIENT AND ECHO SERVER echoserver.c #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<unistd.h> int main(int argc, char **argv) { int clnt_fd,serv_fd; struct sockaddr_in serv_addr; char c; serv_fd=socket(AF_INET,SOCK_STREAM,0); serv_addr.sin_family=AF_INET; serv_addr.sin_port=htons(atoi(argv[1])); serv_addr.sin_addr.s_addr=INADDR_ANY; bind(serv_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); listen(serv_fd,1); clnt_fd=accept(serv_fd, NULL, NULL); while(read(clnt_fd, &c, 1)) write(clnt_fd, &c, 1); close(clnt_fd); close(serv_fd); return 0; } echoclient.c #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<unistd.h> int main(int argc, char **argv) { int clnt_fd; struct sockaddr_in serv_addr; char c; clnt_fd=socket(AF_INET,SOCK_STREAM,0); serv_addr.sin_family=AF_INET; serv_addr.sin_port=htons(atoi(argv[2])); serv_addr.sin_addr.s_addr=inet_addr(argv[1]); connect(clnt_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); while((c=(char)getchar())!=EOF) { write(clnt_fd, &c,1); read(clnt_fd, &c, 1); putchar((int)c); } close(clnt_fd); return 0; } FILE TRANSFER fileserver.c #include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/ioctl.h> #include<net/if_arp.h> #include<arpa/inet.h> int main() { FILE *fp; int sd,cd,b; char fname[50],op[100]; struct sockaddr_in sadd,cadd; socklen_t clen=sizeof(cadd); sd=socket(AF_INET, SOCK_STREAM, 0); if(sd!=-1) printf("Socket is created"); else printf("Socket is not

More about Phase I Essay

Open Document