版本比较
socket搭建的局域网http服务器(http/1.0)
正文
增加 27 行删除 27 行
12342345678241 行未改动全部展开25025125225325425425525625725855 行未改动314315316317318318319320321322172 行未改动全部展开495496497498499499500501502503210 行未改动全部展开714715716717718719720718719720721722723724725722723724725726727728729730731732733734735735736737738739740741742741742743744745746200 行未改动全部展开94794894995095195195295395495595595695795895992 行未改动105210531054105510561056105710581059106059 行未改动1120112111221123112411241125112611271128112911291130113111311132113311341134113511361137113819 行未改动1158115911601161116211621163116411651165116611671168116911701170117111721173117411751175117611771178117933 行未改动# 2.0完整(带文件夹、错误文件):<https://hdkghc.lanzouj.com/ivm1Y1xra1zi> 若不下载完整版,则在EXE文件同目录创建“html”文件夹,是根目录。每个GET操作(目前只支持 GET)和命令都以此为根目录。 第一次运行请输入命令: 完整(带文件夹、错误文件):<https://hdkghc.lanzouj.com/ivm1Y1xra1zi>若不下载完整版,则在EXE文件同目录创建“html”文件夹,是根目录。每个GET操作(目前只支持 GET)和命令都以此为根目录。第一次运行请输入命令:```plainredire ! [路径+你的主页html文件如:/index.html]```---241 行未改动全部展开 { redirect[path] = tmp; return 1; }
}
string Redirect(string url){55 行未改动 syntax.what = what + "\n"; }};
unsigned long long cmdcnt; unsigned long long cmdcnt;queue<pair<unsigned long long, COMMAND>> command;queue<string> cmdresponse;
COMMAND TranslateCommand(string cmd)172 行未改动全部展开 } } if(cmdtp != "!") com.IpFile = DEFFOLDER + cmdtp; else com.IpFile = DEFFOLDER"/";
ss >> cmdtp; if(cmdtp == com.IpFile) { com.err("Htmlpage?");210 行未改动全部展开 ret += to_string(st.wHour) + ":" + to_string(st.wMinute) + ":" + to_string(st.wSecond) + "." + to_string(st.wMilliseconds); return ret;}
void cprintf(int n, int tn, const char *format, ...) { writq.push(make_pair(n, tn)); void cprintf(int n, int tn, const char *format, ...){ writq.push(make_pair(n, tn)); va_list va; char buf[BUFLEN]; va_start(va, format); vsprintf(buf, format, va); va_end(va); char buf[BUFLEN]; va_start(va, format); vsprintf(buf, format, va); va_end(va); string tmp = buf; tmp = to_string(n) + "." + to_string(tn) + "@" + GetFormatTime() + " [LOG] " + tmp; while (writq.front().first != n || writq.front().second != tn) ; // col(n); // col(n); // col(n); // cout << tmp << flush; //// printf(tmp.data()); // col(); for (auto u : tmp) for (auto u : tmp) { col(n); cout << u << flush; // printf("%c", u); // putchar(u); col(); } col(); } fflush(stdout); Sleep(10); writq.pop();}200 行未改动全部展开 { // int pos; // if((pos = has(BWlist.acce, cmd.IpFile)) == -1) BWlist.conf.push_back(cmd.IpFile); // else BWlist.acce.erase(BWlist.acce.begin() + pos);
int pos; if((pos = has(BWlist.acce, cmd.IpFile)) != -1) BWlist.acce.erase(BWlist.acce.begin() + pos); BWlist.conf.push_back(cmd.IpFile);
BWlist.write(); PushCmdResp(cmdcnt, "Done"); } else if(cmd.cmdtype == CMDTYPE::BWLIST)92 行未改动 string s = rece(hRPipe); ++cmdcnt; COMMAND cmd = TranslateCommand(s); ProcessCommand(cmd);
cprintf(35, 0, "Recv num %lld cmd:\n%s\n------\n", cmdcnt, s.data()); } catch(...) {59 行未改动 cout << "create r: "; hRPipe = CreateNamedPipe((pname + "R").data(), PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUF_SIZE, BUF_SIZE, 0, NULL); perr(hRPipe == INVALID_HANDLE_VALUE, "Create Read Pipe Error"); cout << hRPipe << endl;
cout << "create w: "; hWPipe = CreateNamedPipe((pname + "W").data(), PIPE_ACCESS_OUTBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUF_SIZE, BUF_SIZE, 0, NULL); perr(hWPipe == INVALID_HANDLE_VALUE, "Create Write Pipe Error"); cout << hWPipe << endl;
ShellExecuteA(NULL, "open", "httpserver.exe", pname.data(), NULL, SW_SHOWDEFAULT);
perr(!ConnectNamedPipe(hRPipe, NULL) && GetLastError() != ERROR_PIPE_CONNECTED, "Connect R"); perr(!ConnectNamedPipe(hWPipe, NULL) && GetLastError() != ERROR_PIPE_CONNECTED, "Connect W");
CreateThread(NULL, 0, ProcessCommandR, NULL, 0, NULL); CreateThread(NULL, 0, ProcessCommandW, NULL, 0, NULL); SetConsoleTitle("HTTP server main"); if(!IsFileExist(CONFIG))19 行未改动 else { Sleep(1000); pname = argv[1];
perr(!WaitNamedPipe((pname + "R").data(), NMPWAIT_USE_DEFAULT_WAIT), "No Write(main R) Pipe"); perr(!WaitNamedPipe((pname + "W").data(), NMPWAIT_USE_DEFAULT_WAIT), "No Read(main W) Pipe");
cout << "open w(mr) "; hWPipe = CreateFile((pname + "R").data(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); perr(hWPipe == INVALID_HANDLE_VALUE, "Open Write (mR) Pipe Error"); cout << hWPipe << endl;
cout << "open r(mw) "; hRPipe = CreateFile((pname + "W").data(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); perr(hRPipe == INVALID_HANDLE_VALUE, "Open Read (mW) Pipe Error"); cout << hWPipe << endl;
cout << "Input command here:" << endl; unsigned long long i = 0; CreateThread(NULL, 0, CmdProcessResp, NULL, 0, NULL); while(1)33 行未改动