当前位置: 首页>>代码示例>>C++>>正文


C++ EndPoint类代码示例

本文整理汇总了C++中EndPoint的典型用法代码示例。如果您正苦于以下问题:C++ EndPoint类的具体用法?C++ EndPoint怎么用?C++ EndPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EndPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getRemoteAddress

OSS::IPAddress SIPWebSocketConnection::getRemoteAddress() const
/// Returns the last read source address
{
    if (_lastReadAddress.isValid())
        return _lastReadAddress;

    if (_pServerConnection)
    {
        boost::system::error_code ec;
        EndPoint ep = _pServerConnection->get_raw_socket().remote_endpoint(ec);
        if (!ec)
        {
            boost::asio::ip::address ip = ep.address();
            _lastReadAddress = OSS::IPAddress(ip.to_string(), ep.port());
            return _lastReadAddress;
        }
        else
        {
            OSS_LOG_WARNING("SIPWebSocketConnection::getRemoteAddress() Exception " << ec.message());
            return _connectAddress;
        }
    }

    return OSS::IPAddress();

}
开发者ID:ossapp,项目名称:oss_core,代码行数:26,代码来源:SIPWebSocketConnection.cpp

示例2: run

    void run()
    {
        GLock<1> lock;
        std::string msg;
        lock.lock();
        BQueue<std::string>* pBQ = _pMsgHandler->getQueue();
        ICommunicator* pComm = _pMsgHandler->getCommunicator();
        EndPoint remoteEp = _pMsgHandler->getEndPoint();
        lock.unlock();
        ///////////////////////////////////////////////////////
        // insert your server processing here
        while(true)
        {
            sout << locker << "\n  receiver processing message: "
                 << (msg = pBQ->deQ()).c_str() << unlocker;
            lock.lock();
            EndPoint remoteEp = _pMsgHandler->getEndPoint();
            if(pComm->connect(remoteEp.getIP(), remoteEp.getPort()))
            {
                pComm->postMessage(std::string("got message"));
                pComm->disconnect();
            }
            else
                sout << "\n  failed to connect";
            lock.unlock();

            if(msg == "quit")
                break;
        }
        // end of your code
        ///////////////////////////////////////////////////////
    }
开发者ID:Ider,项目名称:SU-Courses,代码行数:32,代码来源:ConsoleRecvr.cpp

示例3: ProcessNewUDPConnectionAttempt

bool NetworkServer::ProcessNewUDPConnectionAttempt(Socket *listenSocket, const EndPoint &endPoint, const char *data, size_t numBytes)
{
	LOG(LogInfo, "New inbound connection attempt from %s with datagram of size %d.", endPoint.ToString().c_str(), (int)numBytes);
	if (!acceptNewConnections)
	{
		LOG(LogError, "Ignored a new connection attempt since server is set not to accept new connections.");
		return false;
	}

	// Pass the datagram contents to a callback that decides whether this connection is allowed.
	if (networkServerListener)
	{
		bool connectionAccepted = networkServerListener->NewConnectionAttempt(endPoint, data, numBytes);
		if (!connectionAccepted)
		{
			LOG(LogError, "Server listener did not accept the new connection.");
			return false;
		}
	}

	///\todo Check IP banlist.
	///\todo Check that the maximum number of active concurrent connections is not exceeded.

	std::string remoteHostName = endPoint.IPToString();

	// Accept the connection and create a new UDP socket that communicates to that endpoint.
	Socket *socket = owner->CreateUDPSlaveSocket(listenSocket, endPoint, remoteHostName.c_str());
	if (!socket)
	{
		LOG(LogError, "Network::ConnectUDP failed! Cannot accept new UDP connection.");
		return false;
	}

	UDPMessageConnection *udpConnection = new UDPMessageConnection(owner, this, socket, ConnectionOK);
	Ptr(MessageConnection) connection(udpConnection);
	{
		PolledTimer timer;
		Lockable<ConnectionMap>::LockType clientsLock = clients.Acquire();
		(*clientsLock)[endPoint] = connection;

		LOG(LogWaits, "NetworkServer::ProcessNewUDPConnectionAttempt: Accessing the connection list took %f msecs.",
			timer.MSecsElapsed());
	}

	// Pass the MessageConnection to the main application so it can hook the inbound packet stream.
	if (networkServerListener)
		networkServerListener->NewConnectionEstablished(connection);

	connection->SendPingRequestMessage(false);

	owner->AssignConnectionToWorkerThread(connection);

	owner->NewMessageConnectionCreated(connection);

	LOG(LogInfo, "Accepted new UDP connection.");
	return true;
}
开发者ID:edwardt,项目名称:kNet,代码行数:57,代码来源:NetworkServer.cpp

示例4: BindEndPoint

void Socket::BindEndPoint(const EndPoint& endpoint)
{
    if(::bind(_sockfd,Socket::sockaddr_cast(&endpoint.GetInternalAddr()),
           static_cast<socklen_t>(sizeof(endpoint.GetInternalAddr()))) < 0)
    {
        int saveErr = errno;
        throw exceptions::ApiExecError("bind", saveErr);
    }
}
开发者ID:MorningCoder,项目名称:simpleton,代码行数:9,代码来源:Socket.cpp

示例5: CREATE_POOL_OBJECT

bool UDPPacketReceiver::processRecv(bool expectingPacket)
{
	Address srcAddr;
	UDPPacket* pChannelReceiveWindow = CREATE_POOL_OBJECT(UDPPacket);
	int len = pChannelReceiveWindow->recvFromEndPoint(*m_pEndPoint, &srcAddr);

	if(len <= 0)
	{
		RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
		PacketReceiver::RecvState rstate = this->checkSocketErrors(len, expectingPacket);
		return rstate == PacketReceiver::RECV_STATE_CONTINUE;
	}

	Channel* pSrcChannel = m_pNetworkInterface->findChannel(srcAddr);
	if(pSrcChannel == NULL)
	{
		EndPoint* pNewEndPoint = CREATE_POOL_OBJECT(EndPoint);

		pNewEndPoint->addr(srcAddr.m_port, srcAddr.m_ip);

		pSrcChannel = CREATE_POOL_OBJECT(Channel, m_pNetworkInterface, pNewEndPoint, nullptr, PROTOCOL_UDP);
		if (!pSrcChannel)
		{
			pSrcChannel->destroy();
			RELEASE_POOL_OBJECT(Channel, pSrcChannel);
			RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
			return false;
		}

		if(!m_pNetworkInterface->registerChannel(pSrcChannel))
		{
			RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
			pSrcChannel->destroy();
			RELEASE_POOL_OBJECT(Channel, pSrcChannel);
			return false;
		}
	}
	SLASSERT(pSrcChannel != NULL, "wtf");

	if(pSrcChannel->isCondemn())
	{
		RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
		m_pNetworkInterface->deregisterChannel(pSrcChannel);
		pSrcChannel->destroy();
		RELEASE_POOL_OBJECT(Channel, pSrcChannel);
		return false;
	}

	Reason ret = this->processPacket(pSrcChannel, pChannelReceiveWindow);

	if(ret != REASON_SUCCESS)
	{

	}

	return true;
}
开发者ID:DuanDechao,项目名称:shyloo,代码行数:57,代码来源:sludp_packet_receiver.cpp

示例6: operator

    virtual int operator()(EndPoint &serverep)
    {
        count = BUFSIZ;

        UseCntPtr<Address> peer(serverep.getInternalAddress().create());

        assert(serverep.read(buf, count, *peer) >= 0);
        assert(serverep.write(buf, count, *peer) >= 0);

        return(0);
    }
开发者ID:ombt,项目名称:ombt,代码行数:11,代码来源:udpepollmsechoserver.cpp

示例7: Bind

void SocketUdp::Bind(const EndPoint& ep)
{
	SOCKADDR_IN	sin;

	if (!ep.getIp())
		 WSAHtonl(this->socket_, INADDR_ANY, &sin.sin_addr.s_addr);
	else
		sin.sin_addr.s_addr = inet_addr(ep.getIpStr().c_str());
	sin.sin_family = AF_INET;
	WSAHtons(this->socket_, ep.getPort(), &sin.sin_port);
	if ((bind(this->socket_, reinterpret_cast<SOCKADDR*>(&sin), sizeof sin)) == SOCKET_ERROR)
		throw ErrorInit("Cannot bind the socket");
}
开发者ID:fiahil,项目名称:R-Type,代码行数:13,代码来源:WinSocketUdp.cpp

示例8: assert

void NetworkServer::ReadUDPSocketData(Socket *listenSocket) // [worker thread]
{
	using namespace std;

	assert(listenSocket);

	OverlappedTransferBuffer *recvData = listenSocket->BeginReceive();
	if (!recvData)
		return; // No datagram available, return.
	if (recvData->bytesContains == 0)
	{
		listenSocket->EndReceive(recvData);
		LOG(LogError, "Received 0 bytes of data in NetworkServer::ReadUDPSocketData!");
		return;
	}
	EndPoint endPoint = EndPoint::FromSockAddrIn(recvData->from); // This conversion is quite silly, perhaps it could be removed to gain performance?
	LOG(LogData, "Received a datagram of size %d to socket %s from endPoint %s.", recvData->bytesContains, listenSocket->ToString().c_str(),
		endPoint.ToString().c_str());

	PolledTimer timer;
	MessageConnection *receiverConnection = 0;

	{
		Lockable<ConnectionMap>::LockType clientsLock = clients.Acquire();
		if (timer.MSecsElapsed() > 50.f)
		{
			LOG(LogWaits, "NetworkServer::ReadUDPSocketData: Accessing the connection list in UDP server receive code took %f msecs.",
			timer.MSecsElapsed());
		}

		ConnectionMap::iterator iter = clientsLock->find(endPoint); ///\todo HashTable for performance.
		if (iter != clientsLock->end())
			receiverConnection = iter->second;
	}

	if (receiverConnection)
	{
		// If the datagram came from a known endpoint, pass it to the connection object that handles that endpoint.
		UDPMessageConnection *udpConnection = dynamic_cast<UDPMessageConnection *>(receiverConnection);
		if (udpConnection)
			udpConnection->QueueInboundDatagram(recvData->buffer.buf, recvData->bytesContains);
		else
			LOG(LogError, "Critical! UDP socket data received into a TCP socket!");
	}
	else
	{
		// The endpoint for this datagram is not known, deserialize it as a new connection attempt packet.
		EnqueueNewUDPConnectionAttempt(listenSocket, endPoint, recvData->buffer.buf, recvData->bytesContains);
	}
	listenSocket->EndReceive(recvData);
}
开发者ID:AGreatFish,项目名称:Urho3D,代码行数:51,代码来源:NetworkServer.cpp

示例9: basicSendSingleTry

//-------------------------------------------------------------------------------------
Reason NetworkInterface::basicSendSingleTry(Channel * pChannel, Packet * pPacket)
{
	EndPoint * endpoint = pChannel->endpoint();
	int len = endpoint->send(pPacket->data(), pPacket->totalSize());

	if (len == (int)pPacket->totalSize())
	{
		return REASON_SUCCESS;
	}
	else
	{
		return NetworkInterface::getSendErrorReason(endpoint, len, pPacket->totalSize());
	}
}
开发者ID:sdsgwangpeng,项目名称:kbengine,代码行数:15,代码来源:network_interface.cpp

示例10: matchesWithEndPoint

// Compares EndPoint ep with itself amd returns true, if they match
// and false otherwise
bool FilterEndPoint::matchesWithEndPoint (const EndPoint & ep, const short & netmask) {
  EndPoint tmp = ep;
  // apply the local netmask of the FilterEndPoint only,
  // if it is smaller than the global netmask
  // (otherwise, nothing would be changed)
  if ( nmask < netmask && nmask > 0 && nmask < 32)
    tmp.applyNetmask(nmask);
  // compare the members and watch out for wildcards
  if ( (tmp.getIpAddress() == ipAddr || nmask == 0)
    && (tmp.getPortNr() == portNr || portNr == -1)
    && (tmp.getProtocolID() == protocolID || protocolID == -1) )
    return true;

  return false;
}
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:17,代码来源:shared.cpp

示例11: createConnection

ConnectionBasePtr TransferNode::createConnection(const PacketBasePtr &packet_base, const EndPoint &ep) {
	PacketHeader::PACKET_ID_TYPE packet_id = packet_base->header.getPacketID();
	if (packet_id == OpenConnection_ID) {
		INFO_LOG("Server: new connection from: " << ep.toString());
		Poco::SharedPtr<OpenConnectionPacket> packet = packet_base.cast<OpenConnectionPacket>();
		assert(packet.get());
		ConnectionBasePtr pConn(new ServerConnection(packet->OpenConnection.Code, ep, this->packet_serializer, *this));
		return pConn;
	} else if (packet_id == OpenConnectionReply_ID) {
		INFO_LOG("Client: new connection to: " << ep.toString());
		Poco::SharedPtr<OpenConnectionReplyPacket> packet = packet_base.cast<OpenConnectionReplyPacket>();
		ConnectionBasePtr pConn(new ClientConnection(packet->OpenConnectionReply.Code, ep, this->packet_serializer, *this));
		return pConn;
	} else {
		throw Poco::ApplicationException("unexpected packet type: ", packet_base->header.getPacketID()); // TODO @@@ ???
	}
}
开发者ID:lulurun,项目名称:fanni,代码行数:17,代码来源:TransferNode.cpp

示例12: operator

    virtual int operator()(EndPoint &clientep)
    {
        char buf[BUFSIZ+1];
        size_t count = BUFSIZ;

        count = clientep.read(buf, count);
        if (count > 0)
        {
            if (clientep.write(buf, count) > 0)
                return(0);
            else
                return(-1);
        }
        else if (count == 0)
            return(1);
        else
            return(-1);
    }
开发者ID:ombt,项目名称:ombt,代码行数:18,代码来源:streamechoserver.cpp

示例13: recvFromEndPoint

//-------------------------------------------------------------------------------------
int UDPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	int len = ep.recvfrom(data(), PACKET_MAX_SIZE_UDP,
		(u_int16_t*)&pAddr->port, (u_int32_t*)&pAddr->ip);

	KBE_ASSERT(rpos() == 0);
	wpos(len);
	return len;
}
开发者ID:Sumxx,项目名称:kbengine,代码行数:10,代码来源:udp_packet.cpp

示例14: KBE_ASSERT

//-------------------------------------------------------------------------------------
int TCPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
{
	//KBE_ASSERT(MessageHandlers::pMainMessageHandlers != NULL && "Must set up a MainMessageHandlers!\n");
	int len = ep.recv(data(), PACKET_MAX_SIZE_TCP * 4);
	KBE_ASSERT(rpos() == 0);
	wpos(len);

	// DEBUG_MSG("TCPPacket::recvFromEndPoint: datasize=%d, wpos=%d.\n", len, wpos());
	return len;
}
开发者ID:sdsgwangpeng,项目名称:kbengine,代码行数:11,代码来源:tcp_packet.cpp

示例15: operator

    virtual int operator()(EndPoint &serverep)
    {
        count = BUFSIZ;

        UseCntPtr<Address> peer(serverep.getInternalAddress().create());

        count = serverep.read(buf, count, *peer);
        if (count > 0)
        {
            if (serverep.write(buf, count, *peer) > 0)
                return(0);
            else
                return(-1);
        }
        else if (count < 0)
            return(-1); // error
        else
            return(1); // EOF -- all done
    }
开发者ID:ombt,项目名称:ombt,代码行数:19,代码来源:datagrammsechoserver.cpp


注:本文中的EndPoint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。