我想binary data
用功能发送send()
职能:
void ssend(const char* data){
send(socket_fd, data, strlen(data), 0);
}
bool readFile(const char* path){
std::ifstream ifile(path);
if(ifile){
if(!ifile.is_open()){
ErrorPage("403");
return true;
}
std::string sLine;
std::string Header = "HTTP/1.1 200 OK\nConnection: Keep-Alive\nKeep-Alive: timeout=5, max=100\nServer: BrcontainerSimpleServer/0.0.1 (Win32) (Whitout Compiler code)\n\n";
ssend(Header.c_str());
while(!ifile.eof()){
getline(ifile, sLine);
cout << "String: " << sLine << endl;
cout << "const char*: " << sLine.c_str() << endl;
ssend(sLine.c_str());
}
return true;
}
return false;
}
测试:
...
while (1) {
socket_fd = accept(listen_fd, (struct sockaddr *)&client_addr,&client_addr_length);
readFile( httpPath );
recv(socket_fd, request, 32768, 0);
closesocket(socket_fd);
}
...
转换为binary string
with 时.c_str()
,数据消失。如何解决这个问题呢?
如何binary data
使用功能发送send()
?