本文整理汇总了C++中sendHeader函数的典型用法代码示例。如果您正苦于以下问题:C++ sendHeader函数的具体用法?C++ sendHeader怎么用?C++ sendHeader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendHeader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetHost
void ESP8266WebServerEx::redirect(const char* homePath) {
uint16_t port = g_ModuleSettings.data.port;
String url;
if ( !homePath ) return;
url.reserve(50);
url = "http://";
url += GetHost();
url += homePath;
String content;
content.reserve(250);
content = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta http-equiv=\"refresh\" content=\"0; URL='";
content += url;
content += "'\" />\n<title>Login</title>\n</head>\n<body onload=\"window.location='";
content += url;
content += "';\">\n</body>\n</html>";
sendHeader("Location",url);
sendHeader("Cache-Control","no-cache");
sendHeader("Pragma","no-cache");
TRACE("Redirect...");
send(302,"text/html",content);
}
示例2: clientPull
/* client function that performs the pull method */
int clientPull(int sock)
{
int numSongs=numSongsInDir();
if(numSongs)
{
if(!sendHeader(2, numSongs*sizeof(song), numSongs, sock))
fatal_error("send header has failed\n");
song *songs=createSongArray(numSongs);
if(!songs)
fatal_error("creating song array failed\n");
if(sendSongArray(songs,numSongs,sock)!=sizeof(song)*numSongs)
fatal_error("sending song array failed\n");
free(songs);
}
else
{
if(!sendHeader(2, 0, 0, sock))
fatal_error("send header has failed\n");
}
header *rcvHead= receiveHeader(sock);
if(!rcvHead)
fatal_error("error receiving rcv header\n");
if(!rcvHead->indexes)
{
fprintf(stderr,"You have all the songs that are on the server.\n\n");
}
else
{
song *rcvSongs=recvSongArray(rcvHead->indexes,sock);
if(!rcvSongs)
fatal_error("error receiving song array\n");
fprintf(stderr, "The following songs have been added to your directory:\n");
int i;
for(i=0;i<rcvHead->indexes;i++)
{
FILE *file = fopen(rcvSongs[i].title,"w+");
if(!receiveFile(file, rcvSongs[i].lenOfSong, sock))
fatal_error("receive file failed\n");
fclose(file);
fprintf(stderr, "%s\n",rcvSongs[i].title);
}
fprintf(stderr,"\n");
free(rcvSongs);
}
free(rcvHead);
return 1;
}
示例3: SendThread
void Sender::startSending()
{
std::thread SendThread(
[&]()
{
do
{
try
{
IMessage *msg = sendQ.deQ();
/*Message* msg = dynamic_cast<Message*>(imsg);
map<string, string> header = msg->getHeader();*/
if (msg->getCommand() == "send_stop")
break;
else if (msg->getCommand() == "file_upload")
{
if (connectToPeer(msg->getRecvIP(), stoi(msg->getRecvPort())))
{
if (sendFile(msg))
{ }
}
else
Verbose::show("Connection failed!\n");
}
else if (msg->getCommand() == "ack")
{
if (connectToPeer(msg->getRecvIP(), stoi(msg->getRecvPort())))
sendHeader(msg);
}
else
{
if (connectToPeer(msg->getRecvIP(), stoi(msg->getRecvPort())))
{
sendHeader(msg);
sendBody(msg);
}
}
}
catch (exception ex)
{
string s = ex.what();
Verbose::show("\n In send Thread: " + s);
}
} while (1);
}
);
SendThread.detach();
}
示例4: String
void ESP8266WebServer::requestAuthentication(HTTPAuthMethod mode, const char* realm, const String& authFailMsg){
if(realm==NULL){
_srealm = "Login Required";
}else{
_srealm = String(realm);
}
if(mode==BASIC_AUTH){
sendHeader("WWW-Authenticate", "Basic realm=\"" + _srealm + "\"");
}else{
_snonce=_getRandomHexString();
_sopaque=_getRandomHexString();
sendHeader("WWW-Authenticate", "Digest realm=\"" +_srealm + "\", qop=\"auth\", nonce=\""+_snonce+"\", opaque=\""+_sopaque+"\"");
}
send(401,"text/html",authFailMsg);
}
示例5: TraceS
void ClientConnection::onSocketConnect()
{
TraceS(this) << "On connect" << endl;
// Set the connection to active
_active = true;
// Emit the connect signal so raw connections like
// websockets can kick off the data flow
Connect.emit(this);
// Start the outgoing send stream if there are
// any queued packets or adapters attached
// startInputStream();
// startOutputStream();
// Flush queued packets
if (!_outgoingBuffer.empty()) {
for (const auto & packet : _outgoingBuffer) {
Outgoing.write(packet.c_str(), packet.length());
}
_outgoingBuffer.clear();
}
// Send the outgoing HTTP header if it hasn't already been sent.
// Note the first call to socket().send() will flush headers.
// Note if there are stream adapters we wait for the stream to push
// through any custom headers. See ChunkedAdapter::emitHeader
if (Outgoing.numAdapters() == 0) {
TraceS(this) << "On connect: Send header" << endl;
sendHeader();
}
}
示例6: sendHeader
bool lwSimpleHTTPClient::post(const char* sensor, double value,unsigned int digits)
{
bool ret;
if (client.connect(LEWEISERVER,80))
{
sendHeader();
client.println(lengthOfInt((int)value)+LENTH+strlen(sensor)+digits);
client.println("Connection: close");
client.println();
client.print("[{\"Name\":\"");
client.print(sensor);
client.print("\",\"Value\":\"");
client.print(value,digits);
client.println ("\"}]");
#ifdef DEBUGGING
Serial.println(lengthOfInt((int)value)+LENTH+strlen(sensor)+digits);
Serial.println("Connection: close");
Serial.println(""); //必须的空白行
Serial.print("[{\"Name\":\"");
Serial.print(sensor);
Serial.print("\",\"Value\":\"");
Serial.print(value, digits);
Serial.println ("\"}]");
#endif // DEBUGGING
ret= true;
}
else
ret=false;
exitHere:
client.stop();
return ret;
}
示例7: send
void ClientConnection::onSocketConnect(net::Socket& socket)
{
// LTrace("On connect")
// Set the connection to active
_active = true;
// Emit the connect signal so raw connections like
// websockets can kick off the data flow
Connect.emit();
// Flush queued packets
if (!_outgoingBuffer.empty()) {
// LTrace("Sending buffered: ", _outgoingBuffer.size())
for (const auto& packet : _outgoingBuffer) {
send(packet.c_str(), packet.length());
}
_outgoingBuffer.clear();
}
else {
// Send the header
sendHeader();
}
// Send the outgoing HTTP header if it hasn't already been sent.
// Note the first call to socket().send() will flush headers.
// Note if there are stream adapters we wait for the stream to push
// through any custom headers. See ChunkedAdapter::emitHeader
//if (Outgoing.numAdapters() == 0) {
// // LTrace("On connect: Send header")
// sendHeader();
//}
}
示例8: clientList
/* client function that performs the list method */
int clientList(int sock)
{
if(!sendHeader(0,0,0, sock))
fatal_error("send header has failed\n");
header *rcvHead= receiveHeader(sock);
if(!rcvHead)
fatal_error("error receiving rcv header\n");
if(!rcvHead->indexes&&!rcvHead->length)
{
free(rcvHead);
fprintf(stderr,"There are no songs on the server.\n\n");
return 1;
}
song *songs=recvSongArray(rcvHead->indexes,sock);
if(!songs)
fatal_error("error receiving song array\n");
fprintf(stderr,"Songs on the server are:\n");
int i;
for(i=0;i<rcvHead->indexes;i++)
{
fprintf(stderr,"%s\n",songs[i].title);
}
fprintf(stderr,"\n");
free((void*)rcvHead);
free((void*)songs);
return 1;
}
示例9: serverLeave
/* sever function that performs the leave method */
int serverLeave(int sock)
{
if(!sendHeader(3,0,0, sock))
fatal_error("send header has failed\n");
return 1;
}
示例10: sendChannel1
void sendChannel1()
{
sendHeader(1);
//analog inputs
for(uint8_t i=0;i < sizeOfArray(channel1);i++) {
AnalogInputs::Name name = pgm::read(&channel1[i]);
uint16_t v = AnalogInputs::getRealValue(name);
printUInt(v);
printD();
}
for(uint8_t i=0;i<MAX_BANANCE_CELLS;i++) {
printUInt(TheveninMethod::getReadableRthCell(i));
printD();
}
printUInt(TheveninMethod::getReadableBattRth());
printD();
printUInt(TheveninMethod::getReadableWiresRth());
printD();
printUInt(Monitor::getChargeProcent());
printD();
printUInt(Monitor::getETATime());
printD();
sendEnd();
}
示例11: selectFile
void selectFile(char *filename)
{
int filesize;
char path[1024];
FILE *file;
if(filename == NULL)
return;
sprintf(path, "/ESIEACloud/%s/%s", actualSession->login, filename);
fprintf(stderr, "path: %s\n", path);
file = fopen(path, "r");
if(file == NULL)
fprintf(stderr, "Ah bah le fichier ne s'ouvre pas\n");
fseek(file, 0L, SEEK_END);
filesize = ftell(file);
fseek(file, 0L, SEEK_SET);
if(file == NULL)
sprintf(actualSession->header, "Content-Type: text/html\r\n\r\nFile Not Found");
else
sprintf(actualSession->header, "Content-Description: File Transfer\r\n"
"Content-Type: application/octet-stream\r\n"
"Content-Disposition: attachment; filename=%s\r\n"
"Content-Transfer-Encoding: binary\r\n"
"Expires: 0\r\n"
"Cache-Control: must-revalidate, post-check=0, pre-check=0\r\n"
"Pragma: public\r\nContent-Length: %d\r\n"
"\r\n", filename, filesize
);
sendHeader();
sendFile(file);
}
示例12: sendHeader
void Junxion::sendData() {
sendHeader(DATA_RESPONSE, _dataSize);
// Send digital input states
uint16_t state = 0;
uint8_t pos = 0;
for (uint8_t i = 0; i < _digitalInputCount; ++i) {
if (_digitalInputs[i].active) {
state = state | (1 << pos);
}
++pos;
if (pos >= 16) {
sendInt16(state);
state = 0;
pos = 0;
}
}
if (pos > 0) {
sendInt16(state);
}
// Send analog pin states
for (uint8_t i = 0; i < _analogInputCount; ++i) {
sendInt16(_analogInputs[i].value);
}
}
示例13: returnError
/**
* sendRequest
* @param type const char * "GET", "POST", ....
* @param payload uint8_t * data for the message body if null not send
* @param size size_t size for the message body if 0 not send
* @return -1 if no info or > 0 when Content-Length is set by server
*/
int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) {
// connect to server
if(!connect()) {
return returnError(HTTPC_ERROR_CONNECTION_REFUSED);
}
if(payload && size > 0) {
addHeader("Content-Length", String(size));
}
// send Header
if(!sendHeader(type)) {
return returnError(HTTPC_ERROR_SEND_HEADER_FAILED);
}
// send Payload if needed
if(payload && size > 0) {
if(_tcp->write(&payload[0], size) != size) {
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
}
}
// handle Server Response (Header)
return returnError(handleHeaderResponse());
}
示例14: sendHeader
void Settings::sendSysInfo()
{
if ( debug )
{
Serial.println ( "[I] Getting sysinfo json" );
}
sendHeader ( 200, "text/json", getSysInfoSize () );
String json = "{";
json += "\"freememory\":\"" + ( String ) ESP.getFreeHeap () + "\",";
json += "\"deauthpackets\":\"" + ( String ) deauthpackets + "\",";
json += "\"beaconpackets\":\"" + ( String ) beaconpackets + "\",";
json += "\"uptime\":\"" + ( String ) millis () + "\",";
json += "\"ipaddress\":\"" + ( String ) WiFi.localIP ().toString () + "\",";
json += "\"gateway\":\"" + ( String ) WiFi.gatewayIP ().toString () + "\",";
json += "\"bootmode\":\"" + ( String ) ESP.getBootMode () + "\",";
json += "\"bootversion\":\"" + ( String ) ESP.getBootVersion () + "\",";
json += "\"sdkversion\":\"" + ( String ) ESP.getSdkVersion () + "\",";
json += "\"chipid\":\"" + ( String ) ESP.getChipId () + "\",";
json += "\"flashchipid\":\"" + ( String ) ESP.getFlashChipId () + "\",";
json += "\"flashchipsize\":\"" + ( String ) ESP.getFlashChipSize () + "\",";
json += "\"flashchiprealsize\":\"" +
( String ) ESP.getFlashChipRealSize () +
"\"}";
sendToBuffer ( json );
sendBuffer ();
if ( debug )
{
Serial.println ( "\n[+] Done" );
}
}
示例15: shared_from_this
void NodeVersionLoader::startDownload()
{
auto self = shared_from_this();
checkThread();
auto& item = currentDownloadItem();
{
std::lock_guard<std::mutex> lock(downloadQueueMutex);
--item.retryCount;
}
state = State::Connecting;
log.setChannel("Download:" + item.version);
std::string fileName;
auto ver = item.version;
try {
onNeedsDownloadFileName(ver, fileName);
if (fileName.empty()) {
MSCThrow(InvalidOperationException("File name is empty."));
}
} catch (...) {
downloadFailed("Failed to determine the downloaded file path.: " +
boost::current_exception_diagnostic_information());
return;
}
try {
file.reset(new std::ofstream(fileName.c_str(),
std::ios::out |
std::ios::trunc |
std::ios::binary));
file->exceptions(std::ios::failbit |
std::ios::badbit);
} catch (...) {
file.reset();
downloadFailed("Failed to open the destination file '" + fileName + "'.: " +
boost::current_exception_diagnostic_information());
return;
}
BOOST_LOG_SEV(log, LogLevel::Info) <<
"Connecting to the master server.";
socket.async_connect(endpoint, [this, self, &item](const error_code& error) {
checkThread();
if (disposed) {
downloadCancelled();
return;
}
if (error) {
downloadFailed(error.message());
return;
}
sendHeader();
});
}