本文整理汇总了C++中TcpConnectionPtr::send方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnectionPtr::send方法的具体用法?C++ TcpConnectionPtr::send怎么用?C++ TcpConnectionPtr::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpConnectionPtr
的用法示例。
在下文中一共展示了TcpConnectionPtr::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnMessage
void OnMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp time_)
{
LOG_DEBUG << conn->name();
size_t len = buf->readableBytes();
while (len >= kCells + 2)
{
const char* crlf = buf->findCRLF();
if (crlf)
{
kimgbo::string request(buf->peek(), crlf);
buf->retrieveUntil(crlf + 2);
len = buf->readableBytes();
if (!processRequest(conn, request))
{
conn->send("Bad Request!\r\n");
conn->shutdown();
break;
}
}
else if (len > 100) // id + ":" + kCells + "\r\n"
{
conn->send("Id too long!\r\n");
conn->shutdown();
break;
}
else
{
break;
}
}
}
示例2: processRequest
bool processRequest(const TcpConnectionPtr& conn, const string& request){
string id;
string puzzle;
bool goodRequest = true;
string::const_iterator colon = find(request.begin(), request.end(), ':');
if(colon != request.end()){
id.assign(request.begin(), colon);
puzzle.assign(colon+1, request.end());
}else{
puzzle = request;
}
if(puzzle.size() == implicit_cast<size_t>(kCells)){
LOG_DEBUG << conn->name();
string result = solveSudoku(puzzle);
if(id.empty()){
conn->send(result+"\r\n");
}else{
conn->send(id +":"+ result+"\r\n" );
}
}else
goodRequest = false;
return goodRequest;
}
示例3: onConnect
void EchoServer::onConnect(const TcpConnectionPtr &conn)
{
cout << "client : " << conn->getPeerAddr().toIp() << " : "
<< conn->getPeerAddr().toPort() << " on" << endl;
conn->send("hello, welcome to Echo Server!\r\nenter word to look for, or q to quit: ");
}
示例4: responseMsg
void ZGWServer::responseMsg(zmq_msg_t& msg_t)
{
size_t msg_size = zmq_msg_size(&msg_t);
assert( msg_size > 0 );
std::string str_msg(static_cast<char*>(zmq_msg_data(&msg_t)), msg_size);
ZMSG msg;
int rc = msg.deserialize(str_msg);
if( rc != 0 )
{
LOG_ERROR << "PULL线程反序列化消息失败, ret: " << rc;
return;
}
//LOG_INFO << "PULL线程反序列化消息成功, msg[id]: " << msg.flow_id << ", msg[type]: "
// << msg.msg_type << ", msg[body size]:" << msg.msg_body.size();
std::map<uint32_t, TcpConnectionPtr>::iterator iter = id2conn_.find(msg.flow_id);
if( iter == id2conn_.end() )
{
LOG_ERROR << "PULL线程查找flow_id: " << msg.flow_id << "对应的连接失败";
return;
}
TcpConnectionPtr conn = iter->second;
muduo::net::Buffer buf;
buf.prependInt8(msg.msg_type);
buf.prependInt32(static_cast<int32_t>(msg.msg_body.size()));
buf.append(msg.msg_body.c_str(), msg.msg_body.size());
conn->send(&buf);
stat_.msg_recv_cnt.increment();
stat_.msg_recv_bytes.addAndGet(msg_size);
}
示例5: compute
void EchoServer::compute(const std::string &word, const TcpConnectionPtr &conn, const TextQuery &tq)
{
if(word == "q")
exit(0);
typedef set<TextQuery::line_no> line_nums;
line_nums locs = tq.run_query(word);
line_nums::size_type size = locs.size();
char ssize[128] = "";
sprintf(ssize, "%d", size);
string s;
s = s + "\n" + word + " occurs " + ssize + " "
+ make_plural(size, "time", "s") + "\n";
line_nums::const_iterator it = locs.begin();
for ( ; it != locs.end(); ++it)
{
char sit[128] = "";
sprintf(sit, "%d", (*it) + 1);
s = s + "\t(line " + sit + ") "
+ tq.text_line(*it) + "\r\n";
}
s = s + "\nenter word to look for, or q to quit: ";
conn->send(s);
}
示例6: messageCallback
void messageCallback(const TcpConnectionPtr& conn, Buffer* buf, Timestamp time)
{
LOG_DEBUG << "---mesageCallback";
string str = buf->retrieveAllAsString();
printf("%s\n", str.c_str());
conn->send(str);
}
示例7: onMessage
void EchoServer::onMessage(const TcpConnectionPtr& conn,
Buffer* buf,
Timestamp time){
string msg(buf->retrieveAllAsString());
LOG_INFO << conn->name() << " echo " << msg.size() << " bytes at " << time.toString();
conn->send(msg);
}
示例8: onMessage
void onMessage(const TcpConnectionPtr& conn, ByteBuffer *buf, Timestamp)
{
++messagesRead_;
bytesRead_ += buf->readableBytes();
bytesWritten_ += buf->readableBytes();
//printf("read : %s\n", buf->toString().c_str());
conn->send(buf);
}
示例9: add
void add(const TcpConnectionPtr& conn)
{
audiences_.insert(conn);
if (lastPubTime_.valid())//这样做,一有sub连上来,就发之前的消息给他
{
conn->send(makeMessage());
}
}
示例10: onTcpConnected
//-----------------------------------------------------------------------------
// 描述: 接受了一个新的TCP连接
//-----------------------------------------------------------------------------
void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection)
{
logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)",
connection->getPeerAddr().getDisplayStr().c_str(),
connection->getServerConnCount());
string msg = "Welcome to the simple echo server, type 'quit' to exit.\r\n";
connection->send(msg.c_str(), msg.length());
}
示例11: sendMyTime
void sendMyTime()
{
if (clientConnection)
{
int64_t message[2] = { 0, 0 };
message[0] = Timestamp::now().microSecondsSinceEpoch();
clientConnection->send(message, sizeof message);
}
}
示例12: onTcpConnected
void ServerModule_Daytime::onTcpConnected(const TcpConnectionPtr& connection)
{
logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)",
connection->getPeerAddr().getDisplayStr().c_str(),
connection->getServerConnCount());
string msg = DateTime::now().toDateTimeString() + "\n";
connection->send(msg.c_str(), msg.length());
}
示例13: connectCallback
void connectCallback( const TcpConnectionPtr& conn)
{
LOG_INFO << "-----------connectionCallback";
string msg = "a";
conn->send(msg);
}
示例14: onMessage
void onMessage(const TcpConnectionPtr& conn,
Buffer* buf,
Timestamp receiveTime)
{
if (buf->findCRLF())
{
conn->send("No such user\r\n");
conn->shutdown();
}
}
示例15: sendDataByClient
void sendDataByClient()
{
static int64_t i = 0;
if (clientConnection)
{
Timestamp now = Timestamp::now();
char str[] = "hello world";
cout << "client send data : " << str << " at " << now.toString() <<"\n";
clientConnection->send(str, sizeof(str));
}
}