本文整理汇总了C++中Network::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::Write方法的具体用法?C++ Network::Write怎么用?C++ Network::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network::Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteBytes
// Write a number of bytes if we can, returning true if we wrote anything
bool Webserver::WriteBytes()
{
Network *net = platform->GetNetwork();
uint8_t i;
for (i = 0; i < 50 && writing && net->CanWrite(); )
{
++i;
if(jsonPointer >= 0)
{
if(jsonResponse[jsonPointer])
{
net->Write(jsonResponse[jsonPointer++]);
}
else
{
jsonPointer = -1;
jsonResponse[0] = 0;
CloseClient();
break;
}
} else
{
char b;
if(fileBeingSent->Read(b))
{
net->Write(b);
}
else
{
fileBeingSent->Close();
CloseClient();
break;
}
}
}
return i != 0;
}
示例2: SendFile
void Webserver::SendFile(const char* nameOfFileToSend)
{
char sLen[SHORT_STRING_LENGTH];
bool zip = false;
if(StringStartsWith(nameOfFileToSend, KO_START))
GetJsonResponse(&nameOfFileToSend[KO_FIRST]);
if(jsonPointer < 0)
{
fileBeingSent = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
if(fileBeingSent == NULL)
{
nameOfFileToSend = FOUR04_FILE;
fileBeingSent = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
}
writing = (fileBeingSent != NULL);
}
Network *net = platform->GetNetwork();
net->Write("HTTP/1.1 200 OK\n");
net->Write("Content-Type: ");
if(StringEndsWith(nameOfFileToSend, ".png"))
net->Write("image/png\n");
else if(StringEndsWith(nameOfFileToSend, ".ico"))
net->Write("image/x-icon\n");
else if (jsonPointer >= 0)
net->Write("application/json\n");
else if(StringEndsWith(nameOfFileToSend, ".js"))
net->Write("application/javascript\n");
else if(StringEndsWith(nameOfFileToSend, ".css"))
net->Write("text/css\n");
else if(StringEndsWith(nameOfFileToSend, ".htm") || StringEndsWith(nameOfFileToSend, ".html"))
net->Write("text/html\n");
else if(StringEndsWith(nameOfFileToSend, ".zip"))
{
net->Write("application/zip\n");
zip = true;
} else
net->Write("application/octet-stream\n");
if (jsonPointer >=0)
{
net->Write("Content-Length: ");
snprintf(sLen, SHORT_STRING_LENGTH, "%d", strlen(jsonResponse));
net->Write(sLen);
net->Write("\n");
}
if(zip)
{
net->Write("Content-Encoding: gzip\n");
net->Write("Content-Length: ");
snprintf(sLen, SHORT_STRING_LENGTH, "%llu", fileBeingSent->Length());
net->Write(sLen);
net->Write("\n");
}
net->Write("Connection: close\n");
net->Write('\n');
}