web server

web server - #include <winsock.h>...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <winsock.h> #include <sys/stat.h> #include <iostream> using namespace std; #define SERVER_PORT 10000 // #define HOSTLEN 256 // #define BACKLOG 10 // int sendall(int s, char *buf, int *len) { int total = 0; // int bytesleft = *len; // int n; while(total < *len) { n = send(s, buf+total, bytesleft, 0); if (n == -1) { break; } total += n; bytesleft -= n; } *len = total; // return n==-1?-1:0; // 0 -1 } void wrong_req(int sock) { char* error_head = "HTTP/1.0 501 Not Implemented\r\n"; //501 int len = strlen(error_head); if (sendall(sock, error_head, &len) == -1) { // printf("Sending failed!"); return; } char* error_type = "Content-type: text/plain\r\n"; len = strlen(error_type); if (sendall(sock, error_type, &len) == -1) { printf("Sending failed!"); return; } char* error_end = "\r\n"; len = strlen(error_end); if (sendall(sock, error_end, &len) == -1) { printf("Sending failed!"); return; } char* prompt_info = "The command is not yet completed\r\n"; len = strlen(prompt_info); if (sendall(sock, prompt_info, &len) == -1) { printf("Sending failed!"); return; } } bool not_exit(char* arguments) { struct stat dir_info; return (stat(arguments, &dir_info) == -1); } void file_not_found(char* arguments, int sock) { char* error_head = "HTTP/1.0 404 Not Found\r\n"; //404head int len = strlen(error_head); if (sendall(sock, error_head, &len) == -1) { // printf("Sending error!"); return; } char* error_type = "Content-type: text/plain\r\n";...
View Full Document

Page1 / 5

web server - #include <winsock.h>...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online