本文整理汇总了C++中Tcp::SendRecv方法的典型用法代码示例。如果您正苦于以下问题:C++ Tcp::SendRecv方法的具体用法?C++ Tcp::SendRecv怎么用?C++ Tcp::SendRecv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tcp
的用法示例。
在下文中一共展示了Tcp::SendRecv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Handle
int Handle(const GwcHead &reqHead, const TReq &reqBody, GwcHead &rspHead, TResp &rspBody) {
string ip = p.GetStr("ip", "127.0.0.1");
uint16_t port = (uint16_t)p.GetU32("port", SERVER_PORT);
uint32_t timeout = p.GetU32("timeout", 10000);
string proto = p.GetStr("proto", "");
char req[0x10000];
uint32_t reqLen = sizeof(req);
mtroe(code(reqHead, reqBody, req, reqLen), "");
char rsp[0x10000];
uint32_t rspLen = sizeof(rsp);
in_addr addr = {inet_addr(ip.c_str())};
printf( "--------------------------------------------------------------------------------\n"
"request host: address=%s:%u, timeout=%u\n"
"request head: msgType=%u, version=%u, bodyLen=%lu\n"
"request body: \n%s"
"--------------------------------------------------------------------------------\n"
, inet_ntoa(addr), port, timeout
, reqHead.msgType, reqHead.version, reqLen - sizeof(reqHead)
, reqBody.DebugString().c_str());
if ("udp" == proto) {
Udp udp;
udp.SetTimeout(timeout);
mtroe(udp.SendRecv(ip, port, req, reqLen, rsp, rspLen), "Udp::SendRecv failed, %s", udp.GetLastErr());
} else {
Tcp tcp;
tcp.SetSendTimeout(timeout);
tcp.SetTimeout(timeout);
mtroe(tcp.SendRecv(ip, port, req, reqLen, rsp, rspLen), "Tcp::SendRecv failed, %s", tcp.GetLastErr());
}
mtroe(decode(rsp, rspLen, rspHead, rspBody), "");
printf("--------------------------------------------------------------------------------\n"
"response head: msgType=%u, version=%u, bodyLen=%lu\n"
"response body: \n%s"
"--------------------------------------------------------------------------------\n"
, rspHead.msgType, rspHead.version, rspLen - sizeof(rspHead)
, rspBody.DebugString().c_str());
return 0;
}