本文整理汇总了C++中endpoint函数的典型用法代码示例。如果您正苦于以下问题:C++ endpoint函数的具体用法?C++ endpoint怎么用?C++ endpoint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了endpoint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: server
static void server()
{
ENetEndpoint endpoint(SOCK_STREAM);
if(endpoint.InitCheck() != E_OK) ETK_ERROR("Failed to create endpoint: %s.", endpoint.ErrorStr());
if(endpoint.Bind(DEFAULT_PORT) != E_OK) ETK_ERROR("Bind(%d) failed: %s.", DEFAULT_PORT, endpoint.ErrorStr());
if(endpoint.Listen() != E_OK) ETK_ERROR("Listen() failed: %s.", endpoint.ErrorStr());
while(true)
{
ETK_OUTPUT("Waiting for client ...\n");
ENetEndpoint *connection = endpoint.Accept(500);
if(connection == NULL)
{
ETK_WARNING("Accept() == NULL: %s.", endpoint.ErrorStr());
continue;
}
struct in_addr addr;
euint16 port;
connection->RemoteAddr().GetAddr(addr, &port);
euint32 ip = E_BENDIAN_TO_HOST_INT32(addr.s_addr);
ETK_OUTPUT("connection from %d.%d.%d.%d, port: %d\n",
ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, port);
EString buf;
time_t curTime = time(NULL);
buf << ctime(&curTime) << "\r\n";
connection->Send(buf.String(), buf.Length());
delete connection;
}
}
示例2: endpoint
void BoostConnection::connect(const HostAddressPort& addressPort) {
boost::asio::ip::tcp::endpoint endpoint(
boost::asio::ip::address::from_string(addressPort.getAddress().toString()), addressPort.getPort());
socket_.async_connect(
endpoint,
boost::bind(&BoostConnection::handleConnectFinished, shared_from_this(), boost::asio::placeholders::error));
}
示例3: endpoint
void Connection::Bind(const std::string & ip, uint16_t port)
{
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(ip), port);
m_socket.open(endpoint.protocol());
m_socket.set_option(boost::asio::ip::tcp::acceptor::reuse_address(false));
m_socket.bind(endpoint);
}
示例4: client
static void client(const char *address)
{
ENetEndpoint endpoint(SOCK_STREAM);
if(endpoint.InitCheck() != E_OK) ETK_ERROR("Failed to create endpoint: %s.", endpoint.ErrorStr());
if(endpoint.Connect(address, DEFAULT_PORT) != E_OK) ETK_ERROR("Connect() failed: %s.", endpoint.ErrorStr());
endpoint.SetTimeout(E_INFINITE_TIMEOUT);
char buf[BUF_SIZE];
size_t pos = 0;
bzero(buf, BUF_SIZE);
while(pos < BUF_SIZE - 1)
{
ETK_OUTPUT("Receiving ...\n");
eint32 bytes = endpoint.Receive(buf + pos, BUF_SIZE - pos - 1);
if(bytes < 0) break;
pos += bytes;
if(pos < 3) continue;
if(buf[pos - 1] == '\n' && buf[pos - 2] == '\r') break;
}
ENetDebug::Enable(true);
ENetDebug::Dump(buf, pos, "Received");
ETK_OUTPUT("Received: %s", buf);
}
示例5: BOOST_FOREACH
void Request::updatePeers(const std::vector<boost::asio::ip::tcp::endpoint>& peers) {
/* filter the new nodes */
BOOST_FOREACH(const boost::asio::ip::tcp::endpoint& peer, peers) {
#ifdef GOLD /* for debugging we need to be able to relay back to the origin */
if (peer == endpoint()) {
continue;
}
#endif
bool seenBefore = false;
BOOST_FOREACH(const boost::asio::ip::tcp::endpoint& old, peers_) {
if (peer == old) {
seenBefore = true;
break;
}
}
BOOST_FOREACH(const boost::asio::ip::tcp::endpoint& old, peersDone_) {
if (peer == old) {
seenBefore = true;
break;
}
}
if (!seenBefore) {
peers_.push_back(peer);
}
}
}
示例6: startpoint
void Wall::ShowStructure(QGraphicsScene *c) {
Vector offset = Cell::Offset();
double factor = Cell::Factor();
Vector startpoint ( ((offset.x+n1->x)*factor),((offset.y+n1->y)*factor)),
endpoint (((offset.x+n2->x)*factor),((offset.y+n2->y)*factor));
Vector linevec = endpoint - startpoint;
Vector midline = startpoint + linevec/2.;
Vector perpvec = linevec.Normalised().Perp2D();
Vector textpos1 = midline + 100 * perpvec;
Vector textpos2 = midline - 100 * perpvec;
QGraphicsLineItem *line = new QGraphicsLineItem(0,c);
line->setPen( QPen(QColor(par.arrowcolor),2) );
line->setLine(startpoint.x, startpoint.y, endpoint.x, endpoint.y );
line->setZValue(10);
line->show();
QGraphicsSimpleTextItem *text1 = new QGraphicsSimpleTextItem( QString("%1").arg(c2->Index()),0,c);
QGraphicsSimpleTextItem *text2 = new QGraphicsSimpleTextItem( QString("%1").arg(c1->Index()),0,c);
text1 -> setPos( textpos1.x, textpos1.y );
text2 -> setPos( textpos2.x, textpos2.y );
text1->setZValue(20); text2->setZValue(20);
text1->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );
text2->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );
text1->setPen ( QColor(par.textcolor) );
text2->setPen ( text1->pen() );
text1->show(); text2->show();
}
示例7: main
int main(int argc, char *argv[])
{
int node_id = 1;
if (argc == 2)
{
node_id = atoi(argv[1]);
}
network::IOServiceThreadManager threads(2);
std::unique_ptr<connector::gw::Client> client;
asio::ip::tcp::endpoint endpoint(asio::ip::address_v4::from_string("127.0.0.1"), 5150);
try
{
client = std::make_unique<connector::gw::Client>(threads, endpoint, 1, gateway::SvrType::kLoginServer, node_id);
}
catch (const std::exception&)
{
std::cerr << "连接网关服务器失败!" << std::endl;
getchar();
exit(1);
}
std::cerr << "连接网关服务器成功!" << std::endl;
client->set_message_callback([](connector::gw::Client *cli, google::protobuf::Message *msg, network::NetMessage &buf)
{
});
threads.run();
return 0;
}
示例8: endpoint
int RTSPServer::Start(unsigned short rtsp_port, std::size_t thread_pool_size)
{
m_rtspListenPort = rtsp_port;
m_threadPoolSize = thread_pool_size;
int iret = -1;
try
{
boost::asio::ip::tcp::endpoint endpoint(
boost::asio::ip::tcp::v4(), m_rtspListenPort);
m_acceptor_.open(endpoint.protocol());
m_acceptor_.bind(endpoint);
m_acceptor_.listen();
StartAccpet();
m_bStoped = false;
iret = 0;
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return iret;
}
示例9: listener_loop
void listener_loop(int port_number)
{
boost::thread workerThread3(updateMeasurement);
boost::asio::io_service io_service;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port_number);
boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint);
while(true)
{
try
{
boost::shared_ptr<boost::asio::ip::tcp::socket> socket = boost::make_shared<boost::asio::ip::tcp::socket>(boost::ref(io_service));
established_connections.push_back(socket);
std::cout << "TCP server ready and listening ... " << std::endl;
acceptor.accept(*established_connections.back());
std::cout << "Number of established client connections: ";
std::cout << established_connections.size() << std::endl;
boost::thread workerThread2(worker,established_connections.back());
}
catch(std::exception& e)
{
std::cerr << "Exception: " << e.what() << std::endl;
}
}
}
示例10: ServiceServer
IPCServer::IPCServer( const std::string & path,
const std::size_t worker_pool_size )
: ServiceServer( worker_pool_size ),
new_connection_(),
acceptor_( io_service_ )
{
unlink( path.c_str() );
try {
asio::local::stream_protocol::endpoint endpoint( path );
acceptor_.open( endpoint.protocol() );
acceptor_.bind( endpoint );
acceptor_.listen();
} catch( boost::system::system_error & e ) {
throw( new IPCServerException( "Unable to create IPC server." ) );
}
try {
start_accept();
} catch( IPCServerException & ipc_e ) {
throw;
}
#ifndef NDEBUG
logger->log( Logger::DEBUG, "IPC server created and accepting connections." );
#endif
}
示例11: endpoint
void RedisAsyncClient::connect(const boost::asio::ip::address &address,
unsigned short port,
std::function<void(bool, const std::string &)> handler)
{
boost::asio::ip::tcp::endpoint endpoint(address, port);
connect(endpoint, std::move(handler));
}
示例12: main
int main(int argc, char *argv[])
{
boost::asio::io_service io;
boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::udp::v4(), 12346);
server s(io, endpoint);
io.run();
return 0;
}
示例13: endpoint
void NoeudThor::startConnectSecureNodeListProvider()
{
noeudSecureNodeListProvider = new Client<NoeudThor>(this, io_service);
tcp::endpoint endpoint(boost::asio::ip::address::from_string(ipSecureNodeListProvider), portSecureNodeListProvider);
cout << "Connection au Secure Node List Provider" << std::endl;
noeudSecureNodeListProvider->getSocket().connect(endpoint);
noeudSecureNodeListProvider->startRead();
}
示例14: endpoint
bool TajoSyncClient::connect(const boost::asio::ip::address &address,
unsigned short port,
std::string &errmsg)
{
tcp::endpoint endpoint(address, port);
return connect(endpoint, errmsg);
}
示例15: StringToEndpoint
udp::endpoint StringToEndpoint(const string &strIpPort)
{
char szIp[16] = {0};
unsigned int dwPort;
sscanf(strIpPort.c_str(), "%[^:]:%d", szIp, &dwPort);
udp::endpoint endpoint(boost::asio::ip::address::from_string(szIp), dwPort);
return endpoint;
}