#include <winsock2.h>
#include <stdio.h>
#include <sys/stat.h>
#pragma comment(lib,"ws2_32.lib")
#define SERVER_PORT 5028
#define HOSTLEN 256
#define BACKLOG 10
int sendall(int s, char *buf, int *len)
{
int total;
int bytesleft;
int n;
total=0;
bytesleft=*len;
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;
}
void wrong_req(int sock)
{
char* error_head = "HTTP/1.1 501 Not Implemented\r\n";
char* error_type = "Content-type: text/plain\r\n";
char* error_end = "\r\n";
char* prompt_info = "The command is not yet completed\r\n";
int len;
len = strlen(error_head);
if (sendall(sock, error_head, &len) == -1)
{
printf("Sending failed!");
return;
}
len = strlen(error_type);
if (sendall(sock, error_type, &len) == -1)
{
printf("Sending failed!");
return;
}
len = strlen(error_end);
if (sendall(sock, error_end, &len) == -1)
{
printf("Sending failed!");
return;
}
len = strlen(prompt_info);
if (sendall(sock, prompt_info, &len) == -1)
{
printf("Sending failed!");
return;
}
}
int not_exit(char* arguments)
{
struct stat dir_info;
if(stat(arguments, &dir_info) =
基于C语言的windows下的web服务器
最新推荐文章于 2024-06-17 18:43:56 发布
本文介绍如何使用C语言在Windows环境下构建一个简单的Web服务器。通过实例展示其运行效果,探讨了C语言编程和Windows系统编程的基础知识。
摘要由CSDN通过智能技术生成