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

C++ enet_initialize函数代码示例

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

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



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

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


示例2: init

	bool CClienteENet::init(unsigned int maxConnections, unsigned int maxinbw, unsigned int maxoutbw)
	{
		if(estado != NO_INIT)
			return false;

		if (enet_initialize () != 0)
		{
			printf ("An error occurred while initializing ENet.\n");
			return false;

		}

		client = enet_host_create (NULL /* create a client host */,
                maxConnections, /* only allow 1 outgoing connection */
                maxinbw ,
                maxoutbw );

		if (client == NULL)
		{
			printf ("An error occurred while trying to create an ENet client host.\n");
			return false;
		}
		if(DEBUG_CLIENT)
			fprintf(stdout, "Client initialized");
	
		estado = INIT_NOT_CONNECTED;

		return true;
	}
开发者ID:franaisa,项目名称:Gloom,代码行数:29,代码来源:clienteENet.cpp


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


示例4: main

int main(int argc, char *argv[] )
{
	FeriteScript *script = NULL;
	char *error_message = NULL;
	
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
	SDL_EnableUNICODE(1);
	
	enet_initialize();
	
	Mix_Init(0);
	
	int audio_rate = 22050;
	Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
	int audio_channels = 2;
	int audio_buffers = 4096;
	Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers);
	
	srand(time(NULL));
	
	if( ferite_init(0, NULL) )
	{
		ferite_set_script_argv(argc, argv);
		script = ferite_script_compile("Game.fe");
		if( ferite_has_compile_error(script) )
		{
			error_message = ferite_get_error_log(script);
			fprintf(stderr, "[ferite: compile]\n%s", error_message);
		}
		else
		{
			ferite_array_init(script);
			ferite_string_init(script);
			ferite_number_init(script);
			game_engine_init(script);
			
			ferite_script_execute(script);
			if( ferite_has_runtime_error(script) )
			{
				error_message = ferite_get_error_log(script);
				fprintf(stderr, "[ferite: execution]\n%s", error_message);
			}
		}
		if( error_message )
		{
			ffree(error_message);
		}
		ferite_script_delete(script);
		ferite_deinit();
	}
	
	enet_deinitialize();
	
	Mix_CloseAudio();
	Mix_Quit();
	
	SDL_Quit();
	
	return 0;
}
开发者ID:snosscire,项目名称:Sky-Raiders,代码行数:60,代码来源:game.c


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


示例6: network_init

void network_init()
{
  ENetAddress address;
  int status, port, max_clients;
  gchar *server;

  network = g_malloc(sizeof(*network));

  server = (gchar *) config_get_string("server", default_server);
  port = config_get_int("port", default_port);
  max_clients = config_get_int("max_clients", default_max_clients);

  status = enet_initialize();
  g_return_if_fail(status == 0);

  enet_address_set_host(&address, server);
  address.port = port;

  network->server = enet_host_create(&address, max_clients, 
#ifdef HAS_RECENT_ENET
                                     2, 
#endif
                                     0, 0);
  g_return_if_fail(network->server != NULL);
  g_debug("Listening on %s:%d", server, port);

  network->clients = NULL;
  g_free(server);
}
开发者ID:acieroid,项目名称:tetristar,代码行数:29,代码来源:network.c


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


示例8: initEnet

void NetworkController::initEnet() {
	if( enet_initialize() != 0){
		root->fatalError("NetController", "Cannot initialise ENet");
	};
	
	root->sout << "Attempting to create host..." << endl;
	
	if( root->confMgr.varExists("host_address") ){
		enet_address_set_host( &enetAddress, root->confMgr.getVarS("host_address").c_str() );
		
		root->sout << "Binding to configured address " << root->confMgr.getVarS("host_address") <<endl;
	}else{
		enetAddress.host = ENET_HOST_ANY;
		root->sout << "Binding to any available address" << endl;
	}
	
	if( root->confMgr.varExists("host_port") ){
		enetAddress.port = root->confMgr.getVarI("host_port");
	}else{
		enetAddress.port = HOST_PORT_DEFAULT;
	}
	
	root->sout << "Binding to port " << enetAddress.port << endl;
	
	enetHost = enet_host_create(&enetAddress, (root->confMgr.varExists("max_clients")) ? (root->confMgr.getVarI("max_clients")) : MAX_CLIENTS_DEFAULT, 2, 0, 0);
	
	if(enetHost == NULL) {
		root->fatalError("NetController", "Cannot create ENet host");
	}
}
开发者ID:cindustries,项目名称:engine-cuboid,代码行数:30,代码来源:NetworkController.cpp


示例9: main

int main (int argc, char ** argv)
{
  if (enet_initialize () != 0)
  {
    fprintf (stderr, "An error occurred while initializing ENet.\n");
    return EXIT_FAILURE;
  }
  atexit (enet_deinitialize);

  ENetAddress address;
  address.host = ENET_HOST_ANY;
  address.port = SOCKK;
  printf("create!\n");
  host = enet_host_create (& address /* 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 (host == NULL)
  {
    fprintf (stderr,
    "An error occurred while trying to create an ENet server host.\n");
    exit (EXIT_FAILURE);
  }

#if EMSCRIPTEN
  emscripten_set_main_loop(main_loop, 3, 1);
#else
  while (1) main_loop();
#endif

  return 1;
}
开发者ID:AIM360,项目名称:emscripten,代码行数:33,代码来源:test_enet_server.c


示例10: pthread_mutex_init

/** Initialises the internal data structures and starts the protocol manager
 *  and the debug console.
 */
void STKHost::init()
{
    m_shutdown         = false;
    m_network          = NULL;
    m_lan_network      = NULL;
    m_listening_thread = NULL;
    m_game_setup       = NULL;
    m_is_registered    = false;
    m_error_message    = "";

    pthread_mutex_init(&m_exit_mutex, NULL);

    // Start with initialising ENet
    // ============================
    if (enet_initialize() != 0)
    {
        Log::error("NetworkConsole", "Could not initialize enet.");
        return;
    }

    Log::info("NetworkConsole", "Host initialized.");
    Network::openLog();  // Open packet log file
    ProtocolManager::getInstance<ProtocolManager>();

    // Optional: start the network console
    m_network_console = new NetworkConsole();
    m_network_console->run();

}   // STKHost
开发者ID:Kumadayo,项目名称:stk-code,代码行数:32,代码来源:stk_host.cpp


示例11: enet_initialize

NetworkManager::NetworkManager() {
	enet_initialize();
	peer = NULL;
	client = NULL;
	isConnectedflag = false;
	endThread = false;
}
开发者ID:quinsmpang,项目名称:xsilium-engine,代码行数:7,代码来源:NetworkManager.cpp


示例12: lock

bool Network::Init(NETWORK_TYPE networkType)
{
    AutoLock<Mutex> lock(m_mutex);

    if(networkType == NONE)
        return false;

    if(enet_initialize() != 0)
    {
        std::cout << "Error initializing network" << std::endl;
        return false;
    }

    if(networkType == CLIENT)
    {
        m_host = enet_host_create (NULL, 1, NETWORK_CHANNEL_COUNT, 0, 0);

        if(!m_host)
        {
            std::cout << "Error initializing connection" << std::endl;
            return false;
        }
    }

    m_type = networkType;
    return true;
}
开发者ID:voidah,项目名称:tak,代码行数:27,代码来源:network.cpp


示例13: Init

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


示例14: Init

    bool Init() {
        if(enet_initialize () < 0)
            return false;

        CubeJ::Init();
        return true;
    }
开发者ID:offtools,项目名称:cubej,代码行数:7,代码来源:remoteclient.cpp


示例15: jsapi_init

void jsapi_init(int filter){
  if(filter){
	ENetCallbacks callbacks = { NULL, NULL, NULL, packet_filter };
        enet_initialize_with_callbacks(ENET_VERSION, &callbacks);
 	return;
  }
  enet_initialize();
}
开发者ID:sunnyboy00,项目名称:enet-npm,代码行数:8,代码来源:jsapi.c


示例16:

///////////////////////////////////////////////////////////////////////////////
/// \brief Network initialization
///
/// It initializes network modules an prepares everything to start creating
/// servers or connecting to peers
///////////////////////////////////////////////////////////////////////////////
void
CNetwork::initialize() {
	// INITIALIZE ENET
	if (enet_initialize() != 0)
		throw "ERROR: There was an error initializing enet and network could"
		" not be started\n";
	m_networkInitialized = true;
}
开发者ID:wen96,项目名称:pl-man2,代码行数:14,代码来源:CNetwork.cpp


示例17: lanarts_net_init

/**
 * Initialize the library
 * return true on success
 */
bool lanarts_net_init(bool throw_on_error) {
	if (enet_initialize() != 0) {
		if (throw_on_error) {
			__lnet_throw_connection_error("Couldn't initialize SDL_net: %s\n");
		}
		return false;
	}
	return true;
}
开发者ID:ludamad,项目名称:lanarts,代码行数:13,代码来源:lanarts_net.cpp


示例18: main

int main(int argc, char **argv)
{
	ENetAddress address;
	ENetHost *server;
	ENetEvent event;
	int eventStatus;

	// a. Initialize enet
	if (enet_initialize() != 0) {
		fprintf(stderr, "An error occured while initializing ENet.\n");
		return EXIT_FAILURE;
	}

	atexit(enet_deinitialize);

	// b. Create a host using enet_host_create
	address.host = ENET_HOST_ANY;
	address.port = 1234;

	server = enet_host_create(&address, 32, 2, 0, 0);

	if (server == NULL) {
		fprintf(stderr, "An error occured while trying to create an ENet server host\n");
		exit(EXIT_FAILURE);
	}

	// c. Connect and user service
	eventStatus = 1;

	while (1) {
		eventStatus = enet_host_service(server, &event, 50000);

		// If we had some event that interested us
		if (eventStatus > 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);
				printf("(Server) We got a new connection from %x\n", event.peer->address.host);
				break;

			case ENET_EVENT_TYPE_RECEIVE:
				printf("(Server) Message from client : %s\n", event.packet->data);
				// Lets broadcast this message to all
				enet_host_broadcast(server, 0, event.packet);
				break;

			case ENET_EVENT_TYPE_DISCONNECT:
				printf("%s disconnected.\n", event.peer->data);
					// Reset client's information
					event.peer->data = NULL;
				break;

			}
		}
	}

}
开发者ID:pdpdds,项目名称:win32opensource2,代码行数:57,代码来源:enetServer.cpp


示例19: udpr_init

/**
	Initialize the Enet library.
**/
static value udpr_init() {
    if (enet_initialize () != 0)
    {
        fprintf (stderr, "An error occurred while initializing ENet.\n");
        exit(EXIT_FAILURE);
    }
    atexit (enet_deinitialize);
    return val_true;
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:12,代码来源:udprsocket.c


示例20: joynet_init

int joynet_init(void)
{
	if(enet_initialize() != 0)
	{
		return 0;
	}
	joynet_detect_endianess();
	return 1;
}
开发者ID:NewCreature,项目名称:JoyNet,代码行数:9,代码来源:joynet.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ enet_list_begin函数代码示例发布时间:2022-05-30
下一篇:
C++ enet_host_flush函数代码示例发布时间: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