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


C++ enet_host_flush函数代码示例

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


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

示例1: ThreadSend

void* ThreadSend() {
    while(1) {
        CCLOG("wait mutex to send");

        mutexMapPlay.lock();
//		pthread_mutex_lock(&mutexMapPlay);
        mapLayerToString(playLayer, packetBuffer);
//		strcpy(packetBuffer, "0000000030000003000000000000000000000010000000000\1");
        ENetPacket * packet = enet_packet_create (packetBuffer,
                              150,
                              ENET_PACKET_FLAG_RELIABLE);
        CCLOG(packet->data);
        /* Send the packet to the peer over channel id 0. */
        /* One could also broadcast the packet by */
        /* enet_host_broadcast (host, 0, packet); */
        enet_peer_send (peer, 0, packet);
        /* One could just use enet_host_service() instead. */
        enet_host_flush (server);
        CCLOG("finish send packet");
    }

    enet_peer_disconnect (peer, 0);
    enet_peer_reset (peer);
    CCLOG("exit thread send");
    return NULL;
}
开发者ID:Group2,项目名称:The-New-Lines,代码行数:26,代码来源:CurlTest.cpp

示例2: net_controller_har_hook

void net_controller_har_hook(int action, void *cb_data) {
    controller *ctrl = cb_data;
    wtf *data = ctrl->data;
    serial ser;
    ENetPeer *peer = data->peer;
    ENetHost *host = data->host;
    ENetPacket *packet;
    if (action == ACT_STOP && data->last_action == ACT_STOP) {
        data->last_action = -1;
        return;
    }
    if (action == ACT_FLUSH) {
        enet_host_flush(host);
        return;
    }
    data->last_action = action;
    serial_create(&ser);
    serial_write_int8(&ser, EVENT_TYPE_ACTION);
    serial_write_int16(&ser, action);
    /*DEBUG("controller hook fired with %d", action);*/
    /*sprintf(buf, "k%d", action);*/
    packet = enet_packet_create(ser.data, ser.len, ENET_PACKET_FLAG_RELIABLE);
    if (peer) {
        enet_peer_send(peer, 1, packet);
        /*enet_host_flush (host);*/
    } else {
        DEBUG("peer is null~");
    }
}
开发者ID:gdeda,项目名称:openomf,代码行数:29,代码来源:net_controller.c

示例3: enet_peer_disconnect_now

/** Force an immediate disconnection from a peer.
    @param peer peer to disconnect
    @remarks No ENET_EVENT_DISCONNECT event will be generated. The foreign peer is not
    guarenteed to receive the disconnect notification, and is reset immediately upon
    return from this function.
*/
void
enet_peer_disconnect_now (ENetPeer * peer)
{
    ENetProtocol command;

    if (peer -> state != ENET_PEER_STATE_DISCONNECTED)
      return;

    if (peer -> state != ENET_PEER_STATE_ZOMBIE &&
        peer -> state != ENET_PEER_STATE_DISCONNECTING)
    {
        enet_peer_reset_queues (peer);

        command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT;
        command.header.channelID = 0xFF;
        command.header.flags = 0;
        command.header.commandLength = sizeof (ENetProtocolDisconnect);

        enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);

        enet_host_flush (peer -> host);
    }

    enet_peer_reset (peer);
}
开发者ID:wangeek,项目名称:Egoboo,代码行数:31,代码来源:peer.c

示例4: enet_host_service

/** Request a disconnection from a peer.
    @param peer peer to request a disconnection
    @param data data describing the disconnection
    @remarks An ENET_EVENT_DISCONNECT event will be generated by enet_host_service()
    once the disconnection is complete.
*/
void
enet_peer_disconnect (ENetPeer * peer, enet_uint32 data)
{
    ENetProtocol command;

    if (peer -> state == ENET_PEER_STATE_DISCONNECTING ||
        peer -> state == ENET_PEER_STATE_DISCONNECTED ||
        peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT ||
        peer -> state == ENET_PEER_STATE_ZOMBIE)
      return;

    enet_peer_reset_queues (peer);

    command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT;
    command.header.channelID = 0xFF;
    command.disconnect.data = ENET_HOST_TO_NET_32 (data);

    if (peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER)
      command.header.command |= ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
    else
      command.header.command |= ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED;      
    
    enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);

    if (peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER)
      peer -> state = ENET_PEER_STATE_DISCONNECTING;
    else
    {
        enet_host_flush (peer -> host);
        enet_peer_reset (peer);
    }
}
开发者ID:Kittnz,项目名称:FoxEmu,代码行数:38,代码来源:peer.cpp

示例5: lock

void Room::RoomImpl::BroadcastRoomInformation() {
    Packet packet;
    packet << static_cast<u8>(IdRoomInformation);
    packet << room_information.name;
    packet << room_information.member_slots;
    packet << room_information.uid;
    packet << room_information.port;
    packet << room_information.preferred_game;

    packet << static_cast<u32>(members.size());
    {
        std::lock_guard<std::mutex> lock(member_mutex);
        for (const auto& member : members) {
            packet << member.nickname;
            packet << member.mac_address;
            packet << member.game_info.name;
            packet << member.game_info.id;
        }
    }

    ENetPacket* enet_packet =
        enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
    enet_host_broadcast(server, 0, enet_packet);
    enet_host_flush(server);
}
开发者ID:namkazt,项目名称:citra,代码行数:25,代码来源:room.cpp

示例6: update_client

void __cdecl update_client(void* a)
{
    for(int i = 0; i < v_clients.size(); ++i)
    {
        // POS il_znakow nick = pozycjaX x pozycjaY

        char buf1[10]; itoa(v_clients[i].nick.size(), buf1, 10);
        char buf2[10]; itoa(v_clients[i].y, buf2, 10);
        char buf3[10]; itoa(v_clients[i].y, buf3, 10);

        string packet = "";
        packet += "POS";
        packet += buf1;
        packet += v_clients[i].nick;
        packet += "=";
        packet += buf2;
        packet += "x";
        packet += buf3;

        ENetPacket *p = enet_packet_create(packet.c_str(), packet.size()+1, ENET_PACKET_FLAG_UNSEQUENCED);
        enet_host_broadcast(server, 1, p);
        enet_host_flush(server);
    }

    updateTime = 0;
}
开发者ID:SeaMonster131,项目名称:mmorpg,代码行数:26,代码来源:main.cpp

示例7: _pop_current_packet

void NetworkedMultiplayerENet::close_connection() {

	if (!active)
		return;

	_pop_current_packet();

	bool peers_disconnected=false;
	for (Map<int,ENetPeer*>::Element *E=peer_map.front();E;E=E->next()) {
		if (E->get()) {
			enet_peer_disconnect_now(E->get(),unique_id);
			peers_disconnected=true;
		}
	}

	if (peers_disconnected) {
		enet_host_flush(host);
		OS::get_singleton()->delay_usec(100); //wait 100ms for disconnection packets to send

	}

	enet_host_destroy(host);
	active=false;
	incoming_packets.clear();
	unique_id=1; //server is 1
	connection_status=CONNECTION_DISCONNECTED;
}
开发者ID:lordadamson,项目名称:godot,代码行数:27,代码来源:networked_multiplayer_enet.cpp

示例8: enet_host_service

/** Request a disconnection from a peer.
    @param peer peer to request a disconnection
    @remarks An ENET_EVENT_DISCONNECT event will be generated by enet_host_service()
    once the disconnection is complete.
*/
void
enet_peer_disconnect (ENetPeer * peer)
{
    ENetProtocol command;

    if (peer -> state == ENET_PEER_STATE_DISCONNECTING ||
        peer -> state == ENET_PEER_STATE_DISCONNECTED ||
        peer -> state == ENET_PEER_STATE_ZOMBIE)
      return;

    enet_peer_reset_queues (peer);

    command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT;
    command.header.channelID = 0xFF;
    command.header.flags = ENET_PROTOCOL_FLAG_UNSEQUENCED;
    command.header.commandLength = sizeof (ENetProtocolDisconnect);

    if (peer -> state == ENET_PEER_STATE_CONNECTED)
      command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;

    enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);

    if (peer -> state == ENET_PEER_STATE_CONNECTED)
      peer -> state = ENET_PEER_STATE_DISCONNECTING;
    else
    {
        enet_host_flush (peer -> host);
        enet_peer_reset (peer);
    }
}
开发者ID:bsegovia,项目名称:cube-gles,代码行数:35,代码来源:peer.c

示例9: enet_packet_create

void ENetServer::broadcastMessage(DeliveryType type, Message::Shared msg) const
{
    if (numClients() == 0) {
        // no clients to broadcast to
        return;
    }

    uint32_t channel = 0;
    uint32_t flags = 0;
    if (type == DeliveryType::RELIABLE) {
        channel = RELIABLE_CHANNEL;
        flags = ENET_PACKET_FLAG_RELIABLE;
    } else {
        channel = UNRELIABLE_CHANNEL;
        flags = ENET_PACKET_FLAG_UNSEQUENCED;
    }

    // get bytes
    auto data = msg->serialize();

    // create the packet
    ENetPacket* p = enet_packet_create(
        &data[0],
        data.size(),
        flags);

    // send the packet to the peer
    enet_host_broadcast(host_, channel, p);
    // flush / send the packet queue
    enet_host_flush(host_);
}
开发者ID:kbirk,项目名称:enet-example,代码行数:31,代码来源:ENetServer.cpp

示例10: val_gc

/**
	Destroy an allocated ENetHost pointer. Must be used with val_gc() for every ENetHost created.
*/
static void destroy_enethost( value h ) {
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enethost\n");
	//exit(0);
#endif
//return;
	if(!val_is_kind(h, k_udprhost))
		return;
	ENetHost *host = (ENetHost *)val_data(h);
	ENetPeer *peer;
	//int x, count;
	if(host == NULL)
		return;
	enet_host_flush( host );
	for (peer = host->peers;
         peer < &host->peers[host->peerCount];
         ++peer)
    {
    	if (peer->state == ENET_PEER_STATE_CONNECTED) {
    		enet_peer_disconnect_now(peer, 0);
    	}
    }

#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enethost\n");
#endif
	enet_host_destroy( host );
	//val_kind(v) = NULL;
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enethost done.\n");
#endif
	return;
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:36,代码来源:udprsocket.c

示例11: getClient

void ENetServer::sendMessage(uint32_t id, DeliveryType type, Message::Shared msg) const
{
    auto client = getClient(id);
    if (!client) {
        // no client to send to
        LOG_WARN("No connected client with id: " << id);
        return;
    }
    uint32_t channel = 0;
    uint32_t flags = 0;
    if (type == DeliveryType::RELIABLE) {
        channel = RELIABLE_CHANNEL;
        flags = ENET_PACKET_FLAG_RELIABLE;
    } else {
        channel = UNRELIABLE_CHANNEL;
        flags = ENET_PACKET_FLAG_UNSEQUENCED;
    }

    // get bytes
    auto data = msg->serialize();
    // create the packet
    ENetPacket* p = enet_packet_create(
        &data[0],
        data.size(),
        flags);

    // send the packet to the peer
    enet_peer_send(client, channel, p);
    // flush / send the packet queue
    enet_host_flush(host_);
}
开发者ID:kbirk,项目名称:enet-example,代码行数:31,代码来源:ENetServer.cpp

示例12: send_callback

/**
 * audio callback.
 */
void send_callback(svc_network_packet_t* packet){
	enet_uint32 src;
	ENetPacket* epacket;

	unsigned char* data;

	/* get ID */
	mutex_lock(&client.network_lock);
	src = client.my_id;

	/* this client didn't get it's ID yet (this also handles connection state as my_id==-1 if not connected)
	 * or is muted. */
	if (src == -1 || client.muted) {
		mutex_unlock(&client.network_lock);
		return;
	}

	/* allocate data */
	data = (unsigned char*)malloc(packet->data_len+10);
	*(enet_uint32*)data = ENET_HOST_TO_NET_32(src);
	*(enet_uint32*)(data + 4) = ENET_HOST_TO_NET_32(packet->data_len+2);
	*(enet_uint16*)(data + 8) = ENET_HOST_TO_NET_16(packet->time);

	/* copy audio data */
	memcpy(data + 10, packet->data, packet->data_len);

	epacket = enet_packet_create(data, packet->data_len + 10, ENET_PACKET_FLAG_UNSEQUENCED);
	enet_peer_send(client.client, 1, epacket);
	enet_host_flush(client.host);
	mutex_unlock(&client.network_lock);

	free(data);
}
开发者ID:atheros,项目名称:svc,代码行数:36,代码来源:main.c

示例13: syncConnectedPlayers

void ListenServerNetMode::sync(GameInstance* instance, ObjectManager* objectManager)
{
    if(m_host)
    {
        // Manage connected players
        syncConnectedPlayers(instance, objectManager);

        // Manage packets from active players
        syncIncomingPackets(objectManager);

        // Manage sending packets to players
        syncOutgoingPackets(objectManager);

        // Connected players have now been served properly so they can become active players
        for(SPlayer* player : m_connectedPlayers)
        {
            player->status = EPlayerStatus::Active;
            m_activePlayers.push_back(player);
        }
        m_connectedPlayers.clear();

        // Flush all created packets
        enet_host_flush(m_host);
    }
}
开发者ID:creepydragon,项目名称:r2,代码行数:25,代码来源:ListenServerNetMode.cpp

示例14: main

int main (int argc, char * const argv[]) {
    
    if(enet_initialize() != 0)
	{
		printf("An error occurred while initializing ENet.\n");
	}
	
	ENetAddress address;
	ENetHost* server;
	
	address.host = ENET_HOST_ANY;
	address.port = 9050;
	
	// up to 32 clients with unlimited bandwidth
	server = enet_host_create(&address, 32, 0, 0);
	if(server == NULL)
	{
		printf("An error occurred while trying to create an ENet server host.\n");
	}
	
	int clients = 0;
	
	// server main loop
	while(true)
	{
		ENetEvent event;
		while(enet_host_service(server, &event, 1000) > 0)
		{
			switch(event.type)
			{
				case ENET_EVENT_TYPE_CONNECT:
					printf ("A new client connected from %x:%u.\n", 
							event.peer -> address.host,
							event.peer -> address.port);
					
					clients++;
					
					break;
					
				case ENET_EVENT_TYPE_RECEIVE:
					printf ("A packet of length %u containing %s was received.\n",
							event.packet->dataLength,
							event.packet->data);
					
					ENetPacket* packet = enet_packet_create(event.packet->data, event.packet->dataLength, ENET_PACKET_FLAG_RELIABLE);
					enet_host_broadcast(server, 0, packet);
					enet_host_flush(server);
					
					enet_packet_destroy(event.packet);
					break;
					
				case ENET_EVENT_TYPE_DISCONNECT:
					printf("Client disconnected.\n");
					event.peer->data = NULL;
			}
		}
	}
	
	return 0;
}
开发者ID:simudream,项目名称:oolong,代码行数:60,代码来源:main.cpp

示例15: disconnect

void disconnect(bool async, bool cleanup)
{
    if(curpeer)
    {
        if(!discmillis)
        {
            enet_peer_disconnect(curpeer, DISC_NONE);
            enet_host_flush(clienthost);
            discmillis = totalmillis;
        }
        if(curpeer->state!=ENET_PEER_STATE_DISCONNECTED)
        {
            if(async) return;
            enet_peer_reset(curpeer);
        }
        curpeer = NULL;
        discmillis = 0;
        conoutf("disconnected");
        game::gamedisconnect(cleanup);
        setvar("mainmenu", 1);
    }
    if(!connpeer && clienthost)
    {
        enet_host_destroy(clienthost);
        clienthost = NULL;
    }
}
开发者ID:ezhangle,项目名称:OF-Engine,代码行数:27,代码来源:client.cpp


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