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


C++ enet_peer_reset函数代码示例

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


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

示例1: destroy_enetpeer

/**
	Destroy an ENetPeer structure.
**/
static void destroy_enetpeer( value p ) {
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enetpeer\n");
	exit(0);
#endif
return;
	ENetPeer *peer;
	if(!val_is_abstract(p) || !val_is_kind(p, k_udprpeer))
		return;
	peer = (ENetPeer *)val_data(p);
	if(peer == NULL)
		return;

	// force immediate disconnect, if still connected.
	enet_peer_disconnect_now(peer, 0);

	// if the peer has an event still, destroy it
	//free_peer_event(peer);

	// clear the peer structure
	enet_peer_reset(peer);

	// peers never need be deallocated, they are part of an ENetHost
#ifdef ENET_DEBUG
	fprintf(stderr, "*** destroy_enetpeer done.\n");
#endif
	return;
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:31,代码来源:udprsocket.c

示例2: shmup_game_network_connect

void
shmup_game_network_connect(shmup_game *g, int network_type, char *hostname)
{
	ENetEvent event;
	ENetAddress address;
	
	g->network_type = network_type;
	if (g->network_type == SERVER) {		
		address.host = ENET_HOST_ANY;
		address.port = 4000;		
		fprintf(stderr, "initializing server on port %d...\n", address.port);
		g->host = enet_host_create(&address, 4, 2, 0, 0);		
	} else {		
		fprintf(stderr, "initializing client...\n");
		enet_address_set_host(&address, hostname);
		address.port = 4000;
		g->host = enet_host_create(NULL, 1, 2, 0, 0);
		g->peer = enet_host_connect(g->host, &address, 2, 0);		
		if (g->peer == NULL) {
			fprintf (stderr, "No available peers for initiating an ENet connection.\n");
			exit (EXIT_FAILURE);
		}		
		if (enet_host_service (g->host, &event, 5000) > 0 &&
		    event.type == ENET_EVENT_TYPE_CONNECT) {
			printf("Connection to %s:4000 succeeded.\n", hostname);
			g->player[g->num_players].pos = v2(g->window_width/2, g->window_height/2);
			g->player[g->num_players].vel = v2zero;
			g->player[g->num_players].acc = v2zero;
			g->num_players++;
		} else {
			enet_peer_reset(g->peer);
			printf("Connection to %s:4000 failed.\n", hostname);
		}
	}
}
开发者ID:GunioRobot,项目名称:ShmupEngine,代码行数:35,代码来源:game.c

示例3: enet_peer_disconnect

	void CClienteENet::disconnect(CConexion* conexion)
	{
		ENetEvent event;
    
		enet_peer_disconnect (((CConexionENet*)conexion)->getENetPeer(),0);

		/* Allow up to 3 seconds for the disconnect to succeed
			and drop any packets received packets.     */
		while (enet_host_service (client, & event, 50) > 0)
		{
			switch (event.type)
			{
			case ENET_EVENT_TYPE_RECEIVE:
				enet_packet_destroy (event.packet);
				break;

			case ENET_EVENT_TYPE_DISCONNECT:
				if(DEBUG_CLIENT)
					fprintf (stdout, "Disconnection succeeded.");
					disconnectReceived(conexion);
				return;
			}
		}
	    
		/* We've arrived here, so the disconnect attempt didn't */
		/* succeed yet.  Force the connection down.             */
		enet_peer_reset (((CConexionENet*)conexion)->getENetPeer());
		disconnectReceived(conexion);

		if(DEBUG_CLIENT)
			fprintf(stdout, "Disconnection Forced");

		if(listaConexiones.empty())
			estado = INIT_NOT_CONNECTED;
	}
开发者ID:franaisa,项目名称:Gloom,代码行数:35,代码来源:clienteENet.cpp

示例4: 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

示例5: CCLOG

void CurlTest::recv(CCObject* pSender)
{
    CCLOG("waiting for connection");
    ENetEvent event;

    while (enet_host_service (server, & event, 10000) > 0) {
        if(event.type==ENET_EVENT_TYPE_CONNECT) {
            CCLOG("connected %x:%u.\n",
                  event.peer -> address.host,
                  event.peer -> address.port);
            char* temp;
            temp = "Client";
            event.peer -> data = temp;
            peer = event.peer;
            initStartGame();

            std::thread threadRecv(ThreadRecv);
            std::thread threadSend(ThreadSend);
            return;
            /*				pthread_t threadRecv;
            				pthread_t threadSend;
            				pthread_create(&threadRecv, NULL, &ThreadRecv, NULL);
            				pthread_create(&threadSend, NULL, &ThreadSend, NULL);	*/
        }
        if(event.type==ENET_EVENT_TYPE_DISCONNECT) {
            CCLOG("%s disconected.\n", event.peer -> data);
            enet_peer_reset (peer);
        }
    }
    pLabel-> setString("time out");
}
开发者ID:Group2,项目名称:The-New-Lines,代码行数:31,代码来源:CurlTest.cpp

示例6: renet_connection_connect

/* The core API functions for a connection: 
  renet_connection_connect
  renet_connection_disconnect
  renet_connection_send_packet
  renet_connection_send_queued_packets
  renet_connection_update
  renet_connection_use_compression
  renet_connection_online
*/
VALUE renet_connection_connect(VALUE self, VALUE timeout)
{
  Connection* connection;
  Data_Get_Struct(self, Connection, connection);
  VALUE lock = rb_iv_get(self, "@lock");
  rb_mutex_lock(lock);

  VALUE rv = Qfalse;

  if (connection->online == 0)
  {
    connection->peer = enet_host_connect(connection->host, connection->address, connection->channels, 0);    
      
    if (connection->peer == NULL)
    {
      rb_raise(rb_eStandardError, "Cannot connect to remote host");
    }
    
    if (service(self, connection, NUM2UINT(timeout)) > 0 && connection->event->type == ENET_EVENT_TYPE_CONNECT)
    {
      connection->online = 1;
      renet_connection_execute_on_connection(self);
      rv = Qtrue;
    }
    else
    {
      enet_peer_reset(connection->peer);
    }
  }

  rb_mutex_unlock(lock);
  return rv;
}
开发者ID:jvranish,项目名称:rENet,代码行数:42,代码来源:renet_connection.c

示例7: enet_peer_disconnect

void NNetwork::Disconnect()
{
    if (!Host)
    {
        return;
    }
    enet_peer_disconnect(Host,0);
    ENetEvent Event;
    while (enet_host_service(Client,&Event,1000) > 0)
    {
        switch (Event.type)
        {
        case ENET_EVENT_TYPE_RECEIVE:
        {
            enet_packet_destroy(Event.packet);
            break;
        }
        case ENET_EVENT_TYPE_DISCONNECT:
        {
            GetGame()->GetLog()->Send("NETWORK",2,std::string("Successfully disconnected with ") + HostName + ".");
            Host = NULL;
            return;
        }
        default:
            GetGame()->GetLog()->Send("NET",1,"Certain events not implemented! FIXME");
            break;
        }
    }
    GetGame()->GetLog()->Send("NETWORK",1,"Server didn't respond to disconnect!");
    enet_peer_reset(Host);
    Host = NULL;
}
开发者ID:ZenX2,项目名称:Astrostruct,代码行数:32,代码来源:NNetwork.cpp

示例8: enet_address_set_host

int NetworkManager::connexionToHost(std::string url,int port)
{
	enet_address_set_host (& address,url.c_str());
	address.port = port;
	peer = enet_host_connect (client, & address, 2, 0);
	if (peer == NULL)
	{
		return 1;
	}
	if (enet_host_service (client, &eventClient, 1000) > 0 && eventClient.type == ENET_EVENT_TYPE_CONNECT)
	{
		isConnectedflag = true;
		endThread = false;
		thread = boost::thread(&NetworkManager::threadConnexion, (void *) this);
		return 0;
	}
	else
	{
		/* Either the 5 seconds are up or a disconnect event was */
		/* received. Reset the peer in the event the 5 seconds   */
		/* had run out without any significant event.            */
		enet_peer_reset (peer);
		return 2 ;
	}
}
开发者ID:quinsmpang,项目名称:xsilium-engine,代码行数:25,代码来源:NetworkManager.cpp

示例9: enet_host_create

void Network::InitializeClient(const char* ipAdress, const short port, const unsigned int maxDownstream, const unsigned int maxUpstream)
{
	std::cout << "Initializing client at port " << port << ".\n";

	_host = enet_host_create (NULL, 1, 2, maxDownstream, maxUpstream);

	if (_host == NULL)
		std::cout << "An error occurred while trying to create an ENet client host.\n";
	else
		std::cout << "Succesfully created ENet client host.\n";

	enet_address_set_host(&_address, ipAdress);
	_address.port = port;

	_peer = enet_host_connect(_host, &_address, 2, 0);

	if (_peer == NULL)
		std::cout << "No available peers for initiating an ENet connection.\n";

	// If connect send packages
	if (enet_host_service(_host, &_event, 1500) > 0 && _event.type == ENET_EVENT_TYPE_CONNECT)
	{
		_isConnected = true;
		printf("Connection to %s:%i succeeded.\n", ipAdress, _address.port);
		StartThreads();	
	}
	else
	{
		enet_peer_reset(_peer);
		printf("Connection to %s:%i failed.\n", ipAdress, _address.port);

	}
}
开发者ID:gametechnology,项目名称:psi-2013,代码行数:33,代码来源:Network.cpp

示例10: lock

NetworkPeer Network::Connect(const std::string& host, unsigned short port, NetworkCallback* callback)
{
    AutoLock<Mutex> lock(m_mutex);

    if(!m_host)
        return NetworkPeer(0);

    if(m_type != CLIENT)
    {
        std::cout << "Connect operation valid only if type is client" << std::endl;
        return NetworkPeer(0);
    }

    ENetAddress address;
    enet_address_set_host(&address, host.c_str());
    address.port = port;

    ENetPeer* peer = enet_host_connect((ENetHost*)m_host, &address, NETWORK_CHANNEL_COUNT, 0);    

    if(!peer)
    {
        std::cout << "Failed to connect to " << host << ":" << port << std::endl;
        return NetworkPeer(0);
    }

    m_networkCallback = callback;

    ENetEvent event;
    if(enet_host_service((ENetHost*)m_host, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT)
        return NetworkPeer(peer);

    enet_peer_reset(peer);
    std::cout << "Failed to connect to " << host << ":" << port << std::endl;
    return NetworkPeer(0);
}
开发者ID:voidah,项目名称:tak,代码行数:35,代码来源:network.cpp

示例11: enet_peer_disconnect

void CHostENet::Disconnect(CPeerENet* pPeer)
{
    ENetEvent event;

    enet_peer_disconnect (pPeer->GetENetPeer(),0);

    /* Allow up to 3 seconds for the disconnect to succeed and drop any packets received packets. */
    while (enet_host_service(m_Host, &event, 3000) > 0)
    {
        switch (event.type)
        {
        case ENET_EVENT_TYPE_RECEIVE:
            enet_packet_destroy (event.packet);
            break;
            
        case ENET_EVENT_TYPE_DISCONNECT:
            if (DEBUG_ENET)
                fprintf (stdout, "Disconnection succeeded.");
                DisconnectReceived(pPeer);
            return;
        }
    }

    /* We've arrived here, so the disconnect attempt didn't succeed yet.  Force the connection down.  */
    enet_peer_reset(pPeer->GetENetPeer());
    DisconnectReceived(pPeer);

    if (DEBUG_ENET)
        fprintf(stdout, "Disconnection Forced");

    if (m_PeerList.empty())
        m_Status = INIT_NOT_CONNECTED;
}
开发者ID:jjimenezg93,项目名称:agarIO,代码行数:33,代码来源:HostENet.cpp

示例12: enet_address_set_host

int NetworkManager::connexionToHost(std::string url,int port)
{
	/* Connect to some.server.net:1234. */
	    enet_address_set_host (& address,url.c_str());
	    address.port = port;

	    /* Initiate the connection, allocating the two channels 0 and 1. */
	    peer = enet_host_connect (client, & address, 2, 0);

	    if (peer == NULL)
	    {
	       return 1;
	    }

	    /* Wait up to 5 seconds for the connection attempt to succeed. */
	    if (enet_host_service (client, &eventClient, 5000) > 0 && eventClient.type == ENET_EVENT_TYPE_CONNECT)
	    {
	    	isConnectedflag = true;
            thread = boost::thread(&NetworkManager::threadConnexion, (void *) this);
	        return 0;
	    }
	    else
	    {
	        /* Either the 5 seconds are up or a disconnect event was */
	        /* received. Reset the peer in the event the 5 seconds   */
	        /* had run out without any significant event.            */
	        enet_peer_reset (peer);
	        return 2 ;
	    }
}
开发者ID:respu,项目名称:xsilium-engine,代码行数:30,代码来源:NetworkManager.cpp

示例13: enet_peer_disconnect

bool udp_client::disconnect()
{
    if (!is_connected())
        return false;

    ENetEvent ev;
    enet_peer_disconnect(peer_, 0);

    {
        boost::lock_guard<boost::mutex> lock(host_mutex_);
        while (enet_host_service(host_, &ev, 3000)) {
            switch (ev.type) {
            case ENET_EVENT_TYPE_DISCONNECT:
                connected_ = false;
                log_msg("udp_client disconnected");
                return true;

            default:
                enet_packet_destroy(ev.packet);
            }
        }
    }

    log_msg("udp_client disconnect failed");
    enet_peer_reset(peer_);
    return false;
}
开发者ID:Nocte-,项目名称:hexahedra,代码行数:27,代码来源:udp_client.cpp

示例14: printf

void CC_Client::connect(const char *host=HOST, uint16_t port=PORT) {
    if (connected) {
        printf("Connected already.\n");
        return;
    }
    
    enet_address_set_host(&address, host);
    address.port = port;
    
    peer = enet_host_connect(client, &address, 2, 0);
    
    if (peer == NULL) {
        fprintf(stderr, "No available peers to connect\n");
        exit(EXIT_FAILURE);
    }
    
    if (enet_host_service(client, &evt, 5000) > 0
        && evt.type == ENET_EVENT_TYPE_CONNECT) {
        printf("Connected to server %s:%u\n", HOST, PORT);
        connected = true;
    } else {
        enet_peer_reset(peer);
        printf("Connection failed to %s:%u\n", HOST, PORT);
    }
    
    //~ conn_t_ret = pthread_create(&conn_t, NULL, CC_Client::loop, (void*)this);
}
开发者ID:noko3,项目名称:cc-client,代码行数:27,代码来源:client.cpp

示例15: while

void Network::Update()
{
	ENetEvent netEvent;
	Event* fwEvent;

	while( enet_host_service( localHost, &netEvent, 0 ) > 0 )
	{
		switch( netEvent.type )
		{
			case ENET_EVENT_TYPE_CONNECT:
				fwEvent = new Event();
				fwEvent->Type = EVENT_NETWORK_CONNECTION_REQUEST;
				memcpy( &fwEvent->Data.Network.Traffic, &netEvent, sizeof(ENetEvent) );
				Framework::System->PushEvent( fwEvent );
				break;

			case ENET_EVENT_TYPE_RECEIVE:
				fwEvent = new Event();
				fwEvent->Type = EVENT_NETWORK_PACKET_RECEIVED;
				memcpy( &fwEvent->Data.Network.Traffic, &netEvent, sizeof(ENetEvent) );
				Framework::System->PushEvent( fwEvent );
				break;

			case ENET_EVENT_TYPE_DISCONNECT:
				enet_peer_reset( netEvent.peer );
				fwEvent = new Event();
				fwEvent->Type = EVENT_NETWORK_DISCONNECTED;
				memcpy( &fwEvent->Data.Network.Traffic, &netEvent, sizeof(ENetEvent) );
				Framework::System->PushEvent( fwEvent );
				break;
		}
	}
}
开发者ID:foxblock,项目名称:Pong,代码行数:33,代码来源:network.cpp


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