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


C++ enet_host_connect函数代码示例

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


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

示例1: enet_address_set_host

    void Host::connect(const std::string &hostname, unsigned int port)
    {
        // set the address of the server to connect to
        enet_address_set_host(&mAddress, hostname.c_str());
        mAddress.port = port;

        // connect to the server
#ifdef ENET_VERSION
        mServer = enet_host_connect(mClient, &mAddress, 0, 1);
#else
        mServer = enet_host_connect (mClient, &mAddress, 1);
#endif
    }
开发者ID:suprafun,项目名称:smalltowns,代码行数:13,代码来源:host.cpp

示例2: mPlayerFactory

    NetManager::NetManager(bool isServer, const FAWorld::PlayerFactory& playerFactory) : mPlayerFactory(playerFactory)
    {
        assert(singletonInstance == NULL);
        singletonInstance = this;

        enet_initialize();

        mAddress.port = 6666;

        mIsServer = isServer;

        if(isServer)
        {
            mAddress.host = ENET_HOST_ANY;
            mHost = enet_host_create(&mAddress, 32, 2, 0, 0);
        }
        else
        {
            enet_address_set_host(&mAddress, "127.0.0.1");
            mHost = enet_host_create(NULL, 32, 2, 0, 0);

            mServerPeer = enet_host_connect(mHost, &mAddress, 2, 0);

            ENetEvent event;

            if(enet_host_service(mHost, &event, 5000))
            {
                std::cout << "connected" << std::endl;
            }
            else
            {
                std::cout << "connection failed" << std::endl;
            }
        }
    }
开发者ID:FlyingTarrasque,项目名称:freeablo,代码行数:35,代码来源:netmanager.cpp

示例3: Disconnect

bool NNetwork::Connect(std::string i_HostName, unsigned int Port)
{
    if (Host)
    {
        Disconnect();
    }
    HostName = i_HostName;
    Address.port = Port;
    enet_address_set_host(&Address, HostName.c_str());

    Host = enet_host_connect(Client,&Address,2,0);
    if (!Host)
    {
        std::stringstream Message;
        Message << "Failed to connect to host " << HostName << " on port " << Port << "!";
        GetGame()->GetLog()->Send("NETWORK",0,Message.str());
        return 1;
    }
    ENetEvent Event;
    if (enet_host_service(Client, &Event, 2500) > 0 && Event.type == ENET_EVENT_TYPE_CONNECT)
    {
        std::stringstream Message;
        Message << "Successfully connected to " << HostName << " on port " << Port << ".";
        GetGame()->GetLog()->Send("NETWORK",2,Message.str());
        return 0;
    } else {
        std::stringstream Message;
        Message << "Failed to connect to host " << HostName << " on port " << Port << "!";
        GetGame()->GetLog()->Send("NETWORK",0,Message.str());
        Host = NULL;
        return 1;
    }
    return 1;
}
开发者ID:ZenX2,项目名称:Astrostruct,代码行数:34,代码来源:NNetwork.cpp

示例4: room_data_change

NetClient::NetClient(const std::string& ip)
:
    me                (0),
    server            (0),
    exit              (false),
    is_game           (false),
    game_start        (false),
    game_end          (false),
    room_data_change  (false),
    player_data_change(false),
    level_change      (false),
    updates_change    (0),
    ourself           (players.begin()) // will crash if dereferenced if empty
{
    // 0 = Client, 1 = one connection at most (to server), 0, 0 = unlim. bandw.
    //
    // #############################################################
    // # NOTE: If you get a compiler error for the following line, #
    // #  check your enet version. Lix assumes you have enet 1.3.  #
    // #############################################################
    me = enet_host_create(0, 1, LEMNET_CHANNEL_MAX, 0, 0);

    ENetAddress address;
    enet_address_set_host(&address, ip.c_str());
    address.port = gloB->server_port;

    server = enet_host_connect(me, &address, LEMNET_CHANNEL_MAX, 0);
}
开发者ID:AmandaBayless,项目名称:Lix,代码行数:28,代码来源:client.cpp

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

示例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_host_create

Network::Network( std::string Server, int Port )
{
	localHost = enet_host_create (NULL /* create a client host */,
		1 /* only allow 1 outgoing connection */,
		1 /* allow up 2 channels to be used, 0 and 1 */,
		// 57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
		// 14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
		0 /* assume any amount of incoming bandwidth */,
		0 /* assume any amount of outgoing bandwidth */);
	if( localHost == 0 )
	{
		return;
	}
	enet_address_set_host( &serverAddress, Server.c_str() );
	serverAddress.port = Port;
	networkPeer = enet_host_connect( localHost, &serverAddress, 1, 0 );
	if( networkPeer == 0 )
	{
		enet_host_destroy( localHost );
		localHost = 0;
		return;
	}

	/* Wait up to 6 seconds for the connection attempt to succeed. */
	ENetEvent ev;
	if( enet_host_service( localHost, &ev, 6000 ) > 0 && ev.type == ENET_EVENT_TYPE_CONNECT )
	{
	} else {
		enet_peer_reset( networkPeer );
		networkPeer = 0;
		enet_host_destroy( localHost );
		localHost = 0;
		return;
	}
}
开发者ID:foxblock,项目名称:Pong,代码行数:35,代码来源:network.cpp

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

示例9: enet_lua_host_connect

int enet_lua_api enet_lua_host_connect(lua_State* L) {
    ENetHost** udata = luaL_checkudata(L, 1, "_enet.host");
    enet_lua_Address_t* address = luaL_checkudata(L, 2, "_enet.address");
    enet_uint32 channels = luaL_checkint(L, 3);
    enet_host_connect(*udata, &address->address_, channels, 0);
    return 0;
}
开发者ID:JoJo2nd,项目名称:Heart,代码行数:7,代码来源:enet_lua.c

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

示例11: ERR_FAIL_COND_V

Error NetworkedMultiplayerENet::create_client(const IP_Address& p_ip,int p_port, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth){

	ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);

	host = enet_host_create (NULL /* create a client host */,
		    1 /* only allow 1 outgoing connection */,
		    p_max_channels /* allow up 2 channels to be used, 0 and 1 */,
		    p_in_bandwidth /* 56K modem with 56 Kbps downstream bandwidth */,
		    p_out_bandwidth /* 56K modem with 14 Kbps upstream bandwidth */);

	ERR_FAIL_COND_V(!host,ERR_CANT_CREATE);


	ENetAddress address;
	address.host=p_ip.host;
	address.port=p_port;

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

	if (peer == NULL) {
		enet_host_destroy(host);
		ERR_FAIL_COND_V(!peer,ERR_CANT_CREATE);
	}

	//technically safe to ignore the peer or anything else.

	connection_status=CONNECTION_CONNECTING;
	active=true;
	server=false;

	return OK;
}
开发者ID:gau-veldt,项目名称:godot,代码行数:33,代码来源:networked_multiplayer_enet.cpp

示例12: CHECK

Peer* ClientHost::Connect(
  std::string server_ip,
  uint16_t port,
  size_t channel_count
) {
  CHECK(_state == STATE_INITIALIZED);

  ENetAddress address;
  if (enet_address_set_host(&address, server_ip.c_str()) != 0) {
    // THROW_ERROR("Unable to set enet host address!");
    return NULL;
  }
  address.port = port;  // XXX: type cast.

  ENetPeer* enet_peer = enet_host_connect(_host, &address, channel_count, 0);
  if (enet_peer == NULL) {
    // THROW_ERROR("Enet host is unable to connect!");
    return NULL;
  }

  Peer* peer = Host::_GetPeer(enet_peer);
  CHECK(peer != NULL);

  return peer;
}
开发者ID:bmteam,项目名称:blowmorph,代码行数:25,代码来源:client_host.cpp

示例13: enet_host_connect

void EnetClient::Connect(void)
{
    std::cout << "before enet_host_connect" << std::endl;
    /* Initiate the connection, allocating the two channels 0 and 1. */
    ENetPeer* peer = enet_host_connect(client_ptr_.get(), &server_addr_, 2, 0);    
    if (peer == NULL)
    {
        fprintf (stderr, "No available peers for initiating an ENet connection.\n");
        exit (EXIT_FAILURE);
    }
    peer_ptr_.reset(peer, enet_peer_reset);

    /* Wait up to 5 seconds for the connection attempt to succeed. */
    ENetEvent event;
    if (enet_host_service(client_ptr_.get(), &event, 5000) > 0 &&
            event.type == ENET_EVENT_TYPE_CONNECT)
    {
        puts ("Connection to some.server.net:1234 succeeded.");
    }
    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.            */
        peer_ptr_.reset();
        puts ("Connection to some.server.net:1234 failed.");
    }
}
开发者ID:libinzhangyuan,项目名称:enet_bench_test,代码行数:28,代码来源:enet_client.cpp

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

示例15: ENSURE

bool CNetClientSession::Connect(u16 port, const CStr& server)
{
	ENSURE(!m_Host);
	ENSURE(!m_Server);

	// Create ENet host
	ENetHost* host = enet_host_create(NULL, 1, CHANNEL_COUNT, 0, 0);
	if (!host)
		return false;

	// Bind to specified host
	ENetAddress addr;
	addr.port = port;
	if (enet_address_set_host(&addr, server.c_str()) < 0)
		return false;

	// Initiate connection to server
	ENetPeer* peer = enet_host_connect(host, &addr, CHANNEL_COUNT, 0);
	if (!peer)
		return false;

	m_Host = host;
	m_Server = peer;

	m_Stats = new CNetStatsTable(m_Server);
	if (CProfileViewer::IsInitialised())
		g_ProfileViewer.AddRootTable(m_Stats);

	return true;
}
开发者ID:Gavinator98,项目名称:0ad,代码行数:30,代码来源:NetSession.cpp


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