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


C++ NetworkPacket类代码示例

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


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

示例1: tcp_recv

DTerr DeviceNetworkSockets::tcp_recv (NetworkPacket &packet, const NetworkSocket &socket)
{
	if (socket.is_empty())
		return DT3_ERR_NONE;

	DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());

    ssize_t size = ::recv(  socket_raw,
                            packet.data(),
                            (DTuint) packet.data_size(),
                            0
                        );
                            

    if (size < 0) {
        packet.set_data_size(0);

        switch (errno) {
            //case EAGAIN:  // Same as EWOULDBLOCK
			case EWOULDBLOCK:	
                return DT3_ERR_NET_WOULD_BLOCK;
			default:			
                LOG_MESSAGE << "TCPRecv: recv: " << strerror(errno) << " (" << (DTuint) errno << ")";
                return DT3_ERR_NET_UNKNOWN;
		};
	} else {
        packet.set_data_size(size);
    }

	return DT3_ERR_NONE;
}
开发者ID:9heart,项目名称:DT3,代码行数:31,代码来源:DeviceNetworkSockets.cpp

示例2: udp_recv

DTerr DeviceNetworkSockets::udp_recv (NetworkPacket &packet, const NetworkSocket &socket)
{    
	if (socket.is_empty())
		return DT3_ERR_NONE;

	DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());

    struct sockaddr from;
    socklen_t       from_size = sizeof(from);

    DTsize size = ::recvfrom(   socket_raw,
                                packet.data(),
                                (DTuint) packet.data_size(),
                                0, 
                                &from,
                                &from_size
                            );
                            
    if (size > 0) {
        packet.set_network_address( address_to_string(&from) );
        packet.set_data_size(size);
    
	} else {	
		switch (errno) {
			case EWOULDBLOCK:	return DT3_ERR_NET_WOULD_BLOCK;
			default:			return DT3_ERR_NET_UNKNOWN;
		};
	}

	return DT3_ERR_NONE;

}
开发者ID:9heart,项目名称:DT3,代码行数:32,代码来源:DeviceNetworkSockets.cpp

示例3: udp_send

DTerr DeviceNetworkSockets::udp_send (const NetworkPacket &packet, const NetworkSocket &socket)
{
	if (socket.is_empty())
		return DT3_ERR_NONE;

	DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());
	
	struct sockaddr_storage sast = string_to_address(packet.network_address().network_address());
    struct sockaddr *sa = (struct sockaddr *) &sast;

#if DT3_OS == DT3_ANDROID
    ::sendto(   socket_raw, 
                packet.data(),
                packet.data_size(),
                0, 
                sa,
                sizeof(sockaddr));
#else
    ::sendto(   socket_raw, 
                packet.data(),
                (DTuint) packet.data_size(),
                0, 
                sa,
                sa->sa_len);
                
#endif

	return DT3_ERR_NONE;
}
开发者ID:9heart,项目名称:DT3,代码行数:29,代码来源:DeviceNetworkSockets.cpp

示例4: shutDown

void Controller::shutDown(void)
{
	NetworkPacket *grid = editor->writeToSerialization();
	
	setDataForUserInterfaceKey("environment", grid->getNetworkLength(), (void *) grid);
	
	free(grid);
}
开发者ID:InfoSphereAC,项目名称:RoboSim,代码行数:8,代码来源:Controller.cpp

示例5: SendServerPacket

void Network::SendServerPacket(NetworkPacket packet, const bool reliable)
{
	if(_isConnected && _isServer)
	{	
		ENetPacket* enetPacket = enet_packet_create(packet.GetBytes(), packet.GetSize(), reliable);

		enet_host_broadcast(_host, 0, enetPacket);
	}
}
开发者ID:gametechnology,项目名称:psi-2013,代码行数:9,代码来源:Network.cpp

示例6: sendPacketToAddress

s32 NetworkBaseUDP::sendPacketToAddress(
    SOCKET Socket, const NetworkPacket &Packet, const sockaddr_in &Address)
{
    /* Send network packet to raw address */
    return sendto(
        Socket,
        Packet.getRealBuffer(),
        Packet.getRealBufferSize(),
        0,
        (sockaddr*)&Address,
        sizeof(sockaddr_in)
    );
}
开发者ID:bekasov,项目名称:SoftPixelEngine,代码行数:13,代码来源:spNetworkBaseUDP.cpp

示例7: remote_input_notify

void MuxDemux :: remote_input_notify(Ticks_t when, void* data, int port)
{
    NetworkPacket* pkt = (NetworkPacket*)data;
    if(pkt->get_type() == CREDIT_MSG_TYPE) {
        //ignore
    }
    else {
        if(m_input_msg_ticks.size() > 0) {
            assert(m_input_msg_ticks.back() <= when);
        }
        m_input_msg_ticks.push_back(when);
    }
}
开发者ID:sixshotx,项目名称:manifold,代码行数:13,代码来源:mux_demux.cpp

示例8: enet_packet_create

void Network::SendPacket(NetworkPacket packet, const bool reliable)
{
	if(_isConnected)
	{
		ENetPacket* enetPacket = enet_packet_create(packet.GetBytes(), packet.GetSize(), reliable);
		if(!_isServer)
			enet_peer_send(_peer, 0, enetPacket);
		else
		{
			_mutex.lock();
			_receivedPackets.push_back(NetworkPacket(enetPacket,0));
			_mutex.unlock();
		}
	}
}
开发者ID:gametechnology,项目名称:psi-2013,代码行数:15,代码来源:Network.cpp

示例9: tcp_send

DTerr DeviceNetworkSockets::tcp_send (const NetworkPacket &packet, const NetworkSocket &socket)
{
	if (socket.is_empty())
		return DT3_ERR_NONE;

	DTint socket_raw = *reinterpret_cast<DTint*>(socket.network_socket_data());
	
    ::send(   socket_raw, 
                packet.data(),
                (DTuint) packet.data_size(),
                0
            );

	return DT3_ERR_NONE;
}
开发者ID:9heart,项目名称:DT3,代码行数:15,代码来源:DeviceNetworkSockets.cpp

示例10: notify_received

void UdpMulticastChannel::notify_received(char* data, size_t sz,boost::asio::ip::udp::endpoint sender_endpoint)
{
    std::vector<unsigned>* lost;
    NetworkPacket* packet = new NetworkPacket;
    if (packet->ParseFromArray(data,sz))
    {
        lost = incoming->add_packet(packet);
        if (lost->size() > 0 )
        {
            send_nack(packet,sender_endpoint,lost);
        }
    }
    //std::cout << "Received: " << sz << " bytes " << std::endl;
    receive_from_network();
}
开发者ID:vagvaz,项目名称:Narukom,代码行数:15,代码来源:udp_multicast_channel.cpp

示例11: while

bool ReceivedPacketProcessor::process() {

    if (_packets.size() == 0) {
        _waitingOnPacketsMutex.lock();
        _hasPackets.wait(&_waitingOnPacketsMutex);
        _waitingOnPacketsMutex.unlock();
    }
    while (_packets.size() > 0) {
        lock(); // lock to make sure nothing changes on us
        NetworkPacket& packet = _packets.front(); // get the oldest packet
        NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
        _packets.erase(_packets.begin()); // remove the oldest packet
        _nodePacketCounts[temporary.getNode()->getUUID()]--;
        unlock(); // let others add to the packets
        processPacket(temporary.getNode(), temporary.getByteArray()); // process our temporary copy
    }
    return isStillRunning();  // keep running till they terminate us
}
开发者ID:BrianPrz,项目名称:hifi,代码行数:18,代码来源:ReceivedPacketProcessor.cpp

示例12: usleep

bool ReceivedPacketProcessor::process() {

    // If a derived class handles process sleeping, like the JurisdiciontListener, then it can set
    // this _dontSleep member and we will honor that request.
    if (_packets.size() == 0 && !_dontSleep) {
        const uint64_t RECEIVED_THREAD_SLEEP_INTERVAL = (1000 * 1000)/60; // check at 60fps
        usleep(RECEIVED_THREAD_SLEEP_INTERVAL);
    }
    while (_packets.size() > 0) {

        lock(); // lock to make sure nothing changes on us
        NetworkPacket& packet = _packets.front(); // get the oldest packet
        NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
        _packets.erase(_packets.begin()); // remove the oldest packet
        unlock(); // let others add to the packets
        processPacket(temporary.getAddress(), temporary.getData(), temporary.getLength()); // process our temporary copy
    }
    return isStillRunning();  // keep running till they terminate us
}
开发者ID:Issacchaos,项目名称:hifi,代码行数:19,代码来源:ReceivedPacketProcessor.cpp

示例13: read_from_network

void UdpMulticastChannel::read_from_network()
{
    boost::asio::ip::udp::endpoint sender_endpoint;
    unsigned int sz = MAX_PACKET_SIZE;
    std::vector<unsigned>* lost;
    char* data = new char[sz];
    receiver->sync_receive(data,sz,&sender_endpoint);
    NetworkPacket* packet = new NetworkPacket;
    if (packet->ParseFromArray(data,sz))
    {
        lost = incoming->add_packet(packet);
        if (lost->size() > 0 )
        {
            //send message to endpoint to resent data
            //sender->sync_send()
        }
    }

    delete data;
}
开发者ID:vagvaz,项目名称:Narukom,代码行数:20,代码来源:udp_multicast_channel.cpp

示例14: DistributePacket

void Network::DistributePacket(NetworkPacket networkPacket)
{
	int type = networkPacket.GetType();
	if (type >= 0 && type < LAST_TYPE)
	{
		std::list<INetworkListener*>::const_iterator iterator;
		for (iterator = _listeners[type]->begin(); iterator != _listeners[type]->end(); ++iterator)
			(*iterator)->HandleNetworkMessage(networkPacket);
	}
	else
		printf("Unknown PacketType '%s' received", type);
}
开发者ID:gametechnology,项目名称:psi-2013,代码行数:12,代码来源:Network.cpp

示例15: usecTimestampNow


//.........这里部分代码省略.........
    // how many packets to send per call

    // We assume you can't possibly call us less than MINIMUM_POSSIBLE_CALL_TIME apart
    if (averageCallTime <= 0) {
        averageCallTime = MINIMUM_POSSIBLE_CALL_TIME;
    }

    // we can determine how many packets we need to send per call to achieve our desired
    // packets per second send rate.
    float callsPerSecond = USECS_PER_SECOND / averageCallTime;

    // theoretically we could get called less than 1 time per second... but since we're using floats, it really shouldn't be
    // possible to get 0 calls per second, but we will guard agains that here, just in case.
    if (callsPerSecond == 0) {
        callsPerSecond = ZERO_RESET_CALLS_PER_SECOND;
    }

    // This is the average number of packets per call...
    averagePacketsPerCall = _packetsPerSecond / callsPerSecond;
    packetsToSendThisCall = averagePacketsPerCall;

    // if we get called more than 1 per second, we want to mostly divide the packets evenly across the calls...
    // but we want to track the remainder and make sure over the course of a second, we are sending the target PPS
    // e.g.
    //     200pps called 60 times per second...
    //     200/60 = 3.333... so really...
    //     each call we should send 3
    //     every 3rd call we should send 4...
    //     3,3,4,3,3,4...3,3,4 = 200...

    // if we get called less than 1 per second, then we want to send more than our PPS each time...
    // e.g.
    //     200pps called ever 1332.5ms
    //     200 / (1000/1332.5) = 200/(0.7505) = 266.5 packets per call
    //     so...
    //        every other call we should send 266 packets
    //        then on the next call we should send 267 packets

    // So no mater whether or not we're getting called more or less than once per second, we still need to do some bookkeeping
    // to make sure we send a few extra packets to even out our flow rate.
    quint64 elapsedSinceLastCheck = now - _lastPPSCheck;

    // we might want to tun this in the future and only check after a certain number of call intervals. for now we check
    // each time and adjust accordingly
    const float CALL_INTERVALS_TO_CHECK = 1;
    const float MIN_CALL_INTERVALS_PER_RESET = 5;

    // we will reset our check PPS and time each second (callsPerSecond) or at least 5 calls (if we get called less frequently
    // than 5 times per second) This gives us sufficient smoothing in our packet adjustments
    float callIntervalsPerReset = std::max(callsPerSecond, MIN_CALL_INTERVALS_PER_RESET);

    if  (elapsedSinceLastCheck > (averageCallTime * CALL_INTERVALS_TO_CHECK)) {
        float ppsOverCheckInterval = (float)_packetsOverCheckInterval;
        float ppsExpectedForCheckInterval = (float)_packetsPerSecond * ((float)elapsedSinceLastCheck / (float)USECS_PER_SECOND);

        if (ppsOverCheckInterval < ppsExpectedForCheckInterval) {
            int adjust = ppsExpectedForCheckInterval - ppsOverCheckInterval;
            packetsToSendThisCall += adjust;
        } else if (ppsOverCheckInterval > ppsExpectedForCheckInterval) {
            int adjust = ppsOverCheckInterval - ppsExpectedForCheckInterval;
            packetsToSendThisCall -= adjust;
        }

        // now, do we want to reset the check interval? don't want to completely reset, because we would still have
        // a rounding error. instead, we check to see that we've passed the reset interval (which is much larger than
        // the check interval), and on those reset intervals we take the second half average and keep that for the next
        // interval window...
        if (elapsedSinceLastCheck > (averageCallTime * callIntervalsPerReset)) {
            // Keep average packets and time for "second half" of check interval
            _lastPPSCheck += (elapsedSinceLastCheck / 2);
            _packetsOverCheckInterval = (_packetsOverCheckInterval / 2);

            elapsedSinceLastCheck = now - _lastPPSCheck;
        }
    }

    int packetsLeft = _packets.size();

    // Now that we know how many packets to send this call to process, just send them.
    while ((packetsSentThisCall < packetsToSendThisCall) && (packetsLeft > 0)) {
        lock();
        NetworkPacket& packet = _packets.front();
        NetworkPacket temporary = packet; // make a copy
        _packets.erase(_packets.begin());
        packetsLeft = _packets.size();
        unlock();

        // send the packet through the NodeList...
        NodeList::getInstance()->writeDatagram(temporary.getByteArray(), temporary.getDestinationNode());
        packetsSentThisCall++;
        _packetsOverCheckInterval++;
        _totalPacketsSent++;
        _totalBytesSent += temporary.getByteArray().size();
        
        emit packetSent(temporary.getByteArray().size());
        
        _lastSendTime = now;
    }
    return isStillRunning();
}
开发者ID:Chris7,项目名称:hifi,代码行数:101,代码来源:PacketSender.cpp


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