aucli - printf"connection with the server...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<stdlib.h> #include<netinet/in.h> #include<sys/types.h> #include<sys/socket.h> #include<netdb.h> #include<string.h> #define PORT 35699 #define MAX 1000 struct Request { char method[10]; char file[10]; char data[1000]; char username[20]; char password[20]; }; struct Response { char data[1000]; // char username1[20]; // char password1[20]; }; int main() { int sockfd; struct sockaddr_in server,client; struct Request req; struct Response res; sockfd=socket(AF_INET,SOCK_STREAM,0); if(sockfd==-1) { printf("socket creation failed...\n"); exit(0); } else printf("Socket successfully created..\n"); bzero(&server,sizeof(server)); server.sin_family=AF_INET; server.sin_addr.s_addr=inet_addr("127.0.0.1"); server.sin_port=htons(PORT);
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { printf("connection with the server failed. ..\n"); exit(0); } else printf("connected to the server. .\n"); printf("\nEnter the username:"); scanf("%s",req.username); printf("\nEnter the password"); scanf("%s",req.password); send(sockfd,&req,sizeof(req),0); printf("\nEnter the method: "); scanf("%s",req.method); printf("\nEnter the file path: "); scanf("%s",req.file); if(!strcmp(req.method,"POST")) { printf("\nEnter data, use ~ to terminate: "); fflush(stdin); scanf("%[^~]",req.data); } send(sockfd,&req,sizeof(req),0); recv(sockfd,&res,sizeof(res),0); printf("Response: %s",res.data); close(sockfd); }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern