• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ enet_host_create函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: m_server

	ServerBase::ServerBase( int port, int maxClients, int numChannels, int incomingBytes /*= 0*/, int outgoingBytes /*= 0*/)
		: m_server(NULL), m_listener(NULL)
	{
		m_keyMsg = "nZGlA5C7pBWTpVCh8xC7Ad";

		m_address.port = port;
		if(port != 0)
		{
			m_address.host = ENET_HOST_ANY;

			m_server = enet_host_create(
				&m_address,maxClients,numChannels,incomingBytes,outgoingBytes);

			if(m_server == NULL)
			{
				throw Exception("Server Host failed to be created!");
			}

		}
		else
		{
			m_server = enet_host_create(
				NULL,1,numChannels,incomingBytes,outgoingBytes);
			if(m_server == NULL)
			{
				throw Exception("Server Client failed to be created!");
			}
		}

	
	}
开发者ID:jmasterx,项目名称:StemwaterSpades,代码行数:31,代码来源:ServerBase.cpp


示例2: enet_address_set_host

bool ConnectionHandler::startListen(enet_uint16 port,
                                    const std::string &listenHost)
{
    // Bind the server to the default localhost.
    address.host = ENET_HOST_ANY;
    address.port = port;

    if (!listenHost.empty())
        enet_address_set_host(&address, listenHost.c_str());

    LOG_INFO("Listening on port " << port << "...");
#if defined(ENET_VERSION) && ENET_VERSION >= ENET_CUTOFF
    host = enet_host_create(
            &address    /* the address to bind the server host to */,
            Configuration::getValue("net_maxClients", 1000) /* allowed connections */,
            0           /* unlimited channel count */,
            0           /* assume any amount of incoming bandwidth */,
            0           /* assume any amount of outgoing bandwidth */);
#else
    host = enet_host_create(
            &address    /* the address to bind the server host to */,
            Configuration::getValue("net_maxClients", 1000) /* allowed connections */,
            0           /* assume any amount of incoming bandwidth */,
            0           /* assume any amount of outgoing bandwidth */);
#endif

    return host != 0;
}
开发者ID:Ablu,项目名称:invertika,代码行数:28,代码来源:connectionhandler.cpp


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


示例4: ERR_FAIL_COND_V

Error GDNetHost::bind(Ref<GDNetAddress> addr) {
	ERR_FAIL_COND_V(_host != NULL, FAILED);

	if (addr.is_null()) {
		_host = enet_host_create(NULL, _max_peers, _max_channels, _max_bandwidth_in, _max_bandwidth_out);
	} else {
		CharString host_addr = addr->get_host().ascii();

		ENetAddress enet_addr;
		enet_addr.port = addr->get_port();

		if (host_addr.length() == 0) {
			enet_addr.host = ENET_HOST_ANY;
		} else {
			if (enet_address_set_host(&enet_addr, host_addr.get_data()) != 0) {
				ERR_EXPLAIN("Unable to resolve host");
				return FAILED;
			}
		}

		_host = enet_host_create(&enet_addr, _max_peers, _max_channels, _max_bandwidth_in, _max_bandwidth_out);
	}

	ERR_FAIL_COND_V(_host == NULL, FAILED);

	thread_start();

	return OK;
}
开发者ID:jrimclean,项目名称:gdnet,代码行数:29,代码来源:gdnet_host.cpp


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


示例6: shmup_game_init

shmup_game *
shmup_game_init()
{
	ENetAddress e;
	shmup_game *g;
	
	g = malloc(sizeof(shmup_game));
	glfwGetWindowSize(&g->window_width, &g->window_height);
	
	g->render_type = 2;
	g->quit = 0;	
	g->emitter = v2(g->window_width / 2, g->window_height / 2);
	g->gravity = v2(0, -250);	
	g->bpool = bpool_new(8000);	
	
	g->bpool->tex[0] = SOIL_load_OGL_texture("./data/flare.tga",
						 SOIL_LOAD_AUTO,
						 SOIL_CREATE_NEW_ID, 0);	
	if(g->bpool->tex[0] == 0)
		fprintf(stderr, "loading error: '%s'\n", SOIL_last_result());
	
	g->bpool->tex[1] = SOIL_load_OGL_texture("./data/arrow.tga",
						 SOIL_LOAD_AUTO,
						 SOIL_CREATE_NEW_ID, 0);
	if(g->bpool->tex[1] == 0)
		fprintf(stderr, "loading error: '%s'\n", SOIL_last_result());	
	
	g->bpool->prog = load_shaders("./data/glsl/bullets.vsh", 
				      "./data/glsl/bullets.fsh");
	
	if (enet_initialize () != 0) {
		fprintf (stderr, "An error occurred while initializing ENet.\n");
		exit(EXIT_FAILURE);
	}
	
	if (g->network_type == SERVER) {
		e.host = ENET_HOST_ANY;
		e.port = 4000;
		g->host = enet_host_create(&e, 4, 2, 0, 0);
	} else {
		g->host = enet_host_create(NULL, 4, 2, 0, 0);
	}
	
	g->player[0].pos = v2(g->window_width/2, g->window_height/2);
	g->player[0].vel = v2zero;
	g->player[0].acc = v2zero;
	
//	fire(g, 1000, 0);
//	fire(g, 1000, 1);
	
	return g;
}
开发者ID:mjard,项目名称:ShmupEngine,代码行数:52,代码来源:game.c


示例7: mServer

    Host::Host():
        mServer(NULL), mConnected(false)
    {
        // create a new client host for connecting to the server
#ifdef ENET_VERSION
        mClient = enet_host_create(NULL, 1, 0, 57600 / 8, 14400 / 8);
#else
        mClient = enet_host_create (NULL /* create a client host */,
                1 /* only allow 1 outgoing connection */,
                57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
                14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
#endif
    }
开发者ID:suprafun,项目名称:smalltowns,代码行数:13,代码来源:host.cpp


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


示例9: enet_address_set_host

bool Room::Create(const std::string& name, const std::string& server_address, u16 server_port,
                  const std::string& password, const u32 max_connections,
                  const std::string& preferred_game, u64 preferred_game_id) {
    ENetAddress address;
    address.host = ENET_HOST_ANY;
    if (!server_address.empty()) {
        enet_address_set_host(&address, server_address.c_str());
    }
    address.port = server_port;

    room_impl->server = enet_host_create(&address, max_connections, NumChannels, 0, 0);
    if (!room_impl->server) {
        return false;
    }
    room_impl->state = State::Open;

    room_impl->room_information.name = name;
    room_impl->room_information.member_slots = max_connections;
    room_impl->room_information.port = server_port;
    room_impl->room_information.preferred_game = preferred_game;
    room_impl->room_information.preferred_game_id = preferred_game_id;
    room_impl->password = password;
    room_impl->CreateUniqueID();

    room_impl->StartLoop();
    return true;
}
开发者ID:namkazt,项目名称:citra,代码行数:27,代码来源:room.cpp


示例10: enet_host_create

void Client::Connect(std::string ip, int port)
{
    client = enet_host_create(NULL, 1, 2, 57600, 14400);
    if(client == NULL) {
        std::cout << "Cannot create client." << std::endl;
    }
}
开发者ID:Kilves,项目名称:ogretest,代码行数:7,代码来源:Client.cpp


示例11: Save

Server::Server(uint16 port, const char *worldId) {
	save = std::unique_ptr<Save>(new Save(worldId));
	boost::filesystem::path path(save->getPath());
	if (!boost::filesystem::exists(path)) {
		boost::filesystem::create_directories(path);
		std::random_device rng;
		boost::random::uniform_int_distribution<uint64> distr;
		uint64 seed = distr(rng);
		save->initialize(worldId, seed);
		save->store();
	}

	ServerChunkManager *cm = new ServerChunkManager(save->getWorldGenerator(), save->getChunkArchive());
	chunkManager = std::unique_ptr<ServerChunkManager>(cm);
	world = std::unique_ptr<World>(new World(chunkManager.get()));

	LOG_INFO(logger) << "Creating server";

	gameServer = std::unique_ptr<GameServer>(new GameServer(this));
	chunkServer = std::unique_ptr<ChunkServer>(new ChunkServer(this));

	if (enet_initialize() != 0)
		LOG_FATAL(logger) << "An error occurred while initializing ENet.";

	ENetAddress address;
	address.host = ENET_HOST_ANY;
	address.port = port;
	host = enet_host_create(&address, MAX_CLIENTS, NUM_CHANNELS, 0, 0);
	if (!host)
		LOG_FATAL(logger) << "An error occurred while trying to create an ENet server host.";
}
开发者ID:Backson,项目名称:3dgamecpp,代码行数:31,代码来源:server.cpp


示例12: EnsureTraversalClient

bool EnsureTraversalClient(const std::string& server, u16 server_port, u16 listen_port)
{
  if (!g_MainNetHost || !g_TraversalClient || server != g_OldServer ||
      server_port != g_OldServerPort || listen_port != g_OldListenPort)
  {
    g_OldServer = server;
    g_OldServerPort = server_port;
    g_OldListenPort = listen_port;

    ENetAddress addr = {ENET_HOST_ANY, listen_port};
    ENetHost* host = enet_host_create(&addr,  // address
                                      50,     // peerCount
                                      1,      // channelLimit
                                      0,      // incomingBandwidth
                                      0);     // outgoingBandwidth
    if (!host)
    {
      g_MainNetHost.reset();
      return false;
    }
    g_MainNetHost.reset(host);
    g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server, server_port));
  }
  return true;
}
开发者ID:Antidote,项目名称:dolphin,代码行数:25,代码来源:TraversalClient.cpp


示例13: renet_connection_initialize

VALUE renet_connection_initialize(VALUE self, VALUE host, VALUE port, VALUE channels, VALUE download, VALUE upload)
{
  rb_funcall(mENet, rb_intern("initialize"), 0);
  Connection* connection;

  /* Now that we're releasing the GIL while waiting for enet_host_service 
     we need a lock to prevent potential segfaults if another thread tries
     to do an operation on same connection  */
  VALUE lock = rb_mutex_new();
  rb_iv_set(self, "@lock", lock); 
  rb_mutex_lock(lock);

  Data_Get_Struct(self, Connection, connection);
  Check_Type(host, T_STRING);
  if (enet_address_set_host(connection->address, StringValuePtr(host)) != 0)
  {
    rb_raise(rb_eStandardError, "Cannot set address");
  }
  connection->address->port = NUM2UINT(port);
  connection->channels = NUM2UINT(channels);
  connection->online = 0;
  connection->host = enet_host_create(NULL, 1, connection->channels, NUM2UINT(download), NUM2UINT(upload));
  if (connection->host == NULL)
  {
    rb_raise(rb_eStandardError, "Cannot create host");
  }
  rb_iv_set(self, "@total_sent_data", INT2FIX(0)); 
  rb_iv_set(self, "@total_received_data", INT2FIX(0));
  rb_iv_set(self, "@total_sent_packets", INT2FIX(0));
  rb_iv_set(self, "@total_received_packets", INT2FIX(0));

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


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


示例15: initEnet

static int initEnet(const char *host_ip, const int host_port, ServerData *data)
{
   ENetAddress address;
   assert(data);

   if (enet_initialize() != 0) {
      fprintf (stderr, "An error occurred while initializing ENet.\n");
      return RETURN_FAIL;
   }

   address.host = ENET_HOST_ANY;
   address.port = host_port;

   if (host_ip)
      enet_address_set_host(&address, host_ip);

   data->server = enet_host_create(&address,
         32    /* max clients */,
         2     /* max channels */,
         0     /* download bandwidth */,
         0     /* upload bandwidth */);

   if (!data->server) {
      fprintf (stderr,
            "An error occurred while trying to create an ENet server host.\n");
      return RETURN_FAIL;
   }

   /* enable compression */
   data->server->checksum = enet_crc32;
   enet_host_compress_with_range_coder(data->server);

   return RETURN_OK;
}
开发者ID:Cloudef,项目名称:srv.birth,代码行数:34,代码来源:main.c


示例16: ERR_FAIL_COND_V

Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth){

	ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);

	ENetAddress address;
	address.host = bind_ip;

	address.port = p_port;

	host = enet_host_create (& address /* the address to bind the server host to */,
				     p_max_clients      /* allow up to 32 clients and/or outgoing connections */,
				     2      /* allow up to 2 channels to be used, 0 and 1 */,
				     p_in_bandwidth      /* assume any amount of incoming bandwidth */,
				     p_out_bandwidth      /* assume any amount of outgoing bandwidth */);

	ERR_FAIL_COND_V(!host,ERR_CANT_CREATE);

	_setup_compressor();
	active=true;
	server=true;
	refuse_connections=false;
	unique_id=1;
	connection_status=CONNECTION_CONNECTED;
	return OK;
}
开发者ID:lordadamson,项目名称:godot,代码行数:25,代码来源:networked_multiplayer_enet.cpp


示例17: enet_address_set_host

    bool GEINetworkServerHost::setServerHost(std::string address, unsigned short netPort,
            size_t peerCount,
            size_t channelLimit,
            int incomingBandwidth,
            int outgoingBandwidth)
    {

        ENetAddress enetAddress;
        if (!address.empty())
        {
            enet_address_set_host (& enetAddress, address.c_str());

            enetAddress.port = netPort;
        }
        else
        {
            enetAddress.host = ENET_HOST_ANY;
            enetAddress.port = netPort;
        }

        enetServerHost = enet_host_create (& enetAddress /* the address to bind the server host to */,
                                 peerCount      /* allow up to 32 clients and/or outgoing connections */,
                                 channelLimit /* allow up to 2 channels to be used, 0 and 1 */,
                                 incomingBandwidth     /* assume any amount of incoming bandwidth */,
                                 outgoingBandwidth /* assume any amount of outgoing bandwidth */);

        if (enetServerHost == NULL)
        {
            fprintf (stderr,
                     "An error occurred while trying to create an ENet server host.\n");
            return false;
        }
        return true;
    }
开发者ID:gestaltdevstudio,项目名称:gei,代码行数:34,代码来源:GEINetworkServerHost.cpp


示例18: L1

void ServerSystem::Init()
{
    if ( enet_initialize () != 0 )
    {
        L1 ( "An error occurred while initializing ENet.\n" );
    }
    atexit ( enet_deinitialize );
    mOnFrameCounterEvent = EventServer<engine::FrameCounterEvent>::Get().Subscribe( boost::bind( &ServerSystem::OnFrameCounterEvent, this, _1 ) );
    mOnClientIdChanged = EventServer<ClientIdChangedEvent>::Get().Subscribe( boost::bind( &ServerSystem::OnClientIdChanged, this, _1 ) );

    /* Bind the server to the default localhost.     */
    /* A specific host address can be specified by   */
    /* enet_address_set_host (& address, "x.x.x.x"); */
    mAddress.host = ENET_HOST_ANY;
    /* Bind the server to port 1234. */
    mAddress.port = 1234;
    mServer = enet_host_create ( & mAddress /* the address to bind the server host to */,
                                 32      /* allow up to 32 clients and/or outgoing connections */,
                                 2      /* allow up to 2 channels to be used, 0 and 1 */,
                                 0      /* assume any amount of incoming bandwidth */,
                                 0      /* assume any amount of outgoing bandwidth */ );
    if ( mServer == NULL )
    {
        L1 ( "An error occurred while trying to create an ENet server host.\n" );
    }
}
开发者ID:HalalUr,项目名称:Reaping2,代码行数:26,代码来源:server_system.cpp


示例19: UdpSocket

UdpSocket * UdpSocket::CreateServer(std::string localHost, int localPort, int maxConnections)
{
    UdpSocket *socket = new UdpSocket();

    // Create ENetHost
    ENetAddress address;
    if ( localHost == "" )
    {
        address.host = ENET_HOST_ANY;
    }
    else
    {
        // TODO
        throw 5;
    }
    address.port = localPort;

    socket->host = enet_host_create(&address, maxConnections, 0, 0);
    if ( !socket->host )
    {
        throw 5; // TODO: Use ri7::core::Exception
    }

    return socket;
}
开发者ID:riseven,项目名称:ri7engine,代码行数:25,代码来源:UdpSocket.cpp


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ enet_host_flush函数代码示例发布时间:2022-05-30
下一篇:
C++ enet_host_connect函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap