本文整理汇总了C++中TCPSocket::Create方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::Create方法的具体用法?C++ TCPSocket::Create怎么用?C++ TCPSocket::Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::Create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
void SocketThread::start()
{
char* json = SocketManager::getInstance()->msgVector.front();
TCPSocket *ts = SocketManager::getInstance()->ts;
ts->Create(AF_INET,SOCK_STREAM,0);
bool iscon=ts->Connect(SocketManager::getInstance()->getAddr(),SocketManager::getInstance()->getPort());
if (iscon)
{
int len = strlen(json);
len = len + 5;
ByteArray *ba = new ByteArray(len);
ba->writeInt(strlen(json));
ba->writeByte(0);
ba->writeString(json);
ts->Send(ba->getByteArray(), len);
} else {
printf("TCPSOCKET ERROR : connect failed!");
}
char* buff;
ts->Recv(buff);
resposeMsg(buff);
}
示例2: BaseCommand
void TCPConnection::BaseCommand(Params &request, ProcessDone_cb callback)
{
Params result = request;
if (request["0"] == "version")
{
cDebugDom("network") << "version";
if (request["1"] == "?")
result.Add("1", Utils::get_config_option("fw_version"));
}
else if (request["0"] == "save")
{
cDebugDom("network") << "save";
Config::Instance().SaveConfigIO();
Config::Instance().SaveConfigRule();
if (request["1"] == "default")
{
//copy the default config files
Utils::file_copy(ETC_DIR"io.xml", "/mnt/ext3/calaos/io.default");
Utils::file_copy(ETC_DIR"rules.xml", "/mnt/ext3/calaos/rules.default");
}
}
else if (request["0"] == "system")
{
cDebugDom("network") << "system";
if (request["1"] == "reboot")
{
if (request["2"] == "calaos_gui")
{
int unused = system("killall -9 calaos_gui");
unused = system("killall -9 calaos_thumb");
(void)unused;
}
else if (request["2"] == "calaosd")
{
int unused = system("killall -9 calaosd");
(void)unused;
}
else if (request["2"] == "all")
{
int unused = system("reboot");
(void)unused;
}
}
else if(request["1"] == "date")
{
vector<string> vcmd;
for(int i=0;i<request.size();i++)
{
string s = Utils::to_string(i);
vcmd.push_back(request[s]);
}
NTPClock::Instance().setNetworkCmdCalendarApply(vcmd);
NTPClock::Instance().setRestartWhenApply(false);
IPC::Instance().SendEvent("CalaosCommon::NTPClock","applyCalendar",NULL);
result.Add("2", "ok");
string cmd = "";
for(int i=0;i<9;i++)
cmd+=request[Utils::to_string(i)]+" ";
//envoie de la commandes aux clients
TCPSocket *sock;
sock = new TCPSocket;
sock->Create(UDP);
sock->Broadcast(cmd, BCAST_UDP_PORT);
sock->Close();
delete sock;
}
}
else if (request["0"] == "firmware")
{
cDebugDom("network") << "firmware";
if (request["1"] == "webupdate")
{
//try to update firmware from /tmp/image.tar.bz2
cDebugDom("network") << "save: Firmware update requested by web.";
int unused = system("fw_update.sh");
(void)unused;
}
}
else if (request["0"] == "poll_listen")
{
cDebugDom("network") << "poll_listen";
if (request["1"] == "register")
{
string uuid = PollListenner::Instance().Register();
result.Add("2", uuid);
}
else if (request["1"] == "unregister")
{
if (PollListenner::Instance().Unregister(request["2"]))
result.Add("2", "true");
else
result.Add("2", "false");
//.........这里部分代码省略.........