16 Star 91 Fork 31

ithewei / libhv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
UdpServer_test.cpp 951 Bytes
一键复制 编辑 原始数据 按行查看 历史
ithewei 提交于 2021-01-23 20:27 . evpp: c++ classes of event
/*
* UdpServer_test.cpp
*
* @build
* make libhv && sudo make install
* g++ -std=c++11 UdpServer_test.cpp -o UdpServer_test -I/usr/local/include/hv -lhv -lpthread
*
*/
#include "UdpServer.h"
using namespace hv;
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Usage: %s port\n", argv[0]);
return -10;
}
int port = atoi(argv[1]);
UdpServer srv;
int bindfd = srv.createsocket(port);
if (bindfd < 0) {
return -20;
}
printf("server bind on port %d, bindfd=%d ...\n", port, bindfd);
srv.onMessage = [](const SocketChannelPtr& channel, Buffer* buf) {
// echo
printf("< %.*s\n", (int)buf->size(), (char*)buf->data());
channel->write(buf);
};
srv.onWriteComplete = [](const SocketChannelPtr& channel, Buffer* buf) {
printf("> %.*s\n", (int)buf->size(), (char*)buf->data());
};
srv.start();
while (1) sleep(1);
return 0;
}
C
1
https://gitee.com/ithewei/libhv.git
git@gitee.com:ithewei/libhv.git
ithewei
libhv
libhv
master

搜索帮助