コード例 #1
3
ファイル: main.c プロジェクト: Cloudef/srv.birth
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;
}
コード例 #2
1
ファイル: Network.cpp プロジェクト: kiwon0905/Unnamed-Project
bool Network::initialize(Client & client)
{
	if (enet_initialize() != 0)
		return false;

	m_client = enet_host_create(nullptr, 1, 1, 0, 0);
	if (!m_client)
		return false;
	if (enet_host_compress_with_range_coder(m_client) < 0)
		return false;
	m_socket = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
	if (m_socket < 0)
		return false;
	if (enet_socket_set_option(m_socket, ENET_SOCKOPT_NONBLOCK, 1) < 0)
		return false;
	if (enet_socket_set_option(m_socket, ENET_SOCKOPT_BROADCAST, 1) < 0)
		return false;
	return true;
}
コード例 #3
0
void NetworkManager::createConnexion()
{
	client = enet_host_create (NULL /* create a client host */,
	                1 /* only allow 1 outgoing connection */,
	                2 /* 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 */);
	if ( client != NULL)
		enet_host_compress_with_range_coder(client);
}
コード例 #4
0
ファイル: renet_server.c プロジェクト: Dahrkael/rENet
VALUE renet_server_use_compression(VALUE self, VALUE flag)
{
    Server* server;
    Data_Get_Struct(self, Server, server);
    VALUE lock = rb_iv_get(self, "@lock");
    rb_mutex_lock(lock);
    if (flag == Qtrue)
    {
        enet_host_compress_with_range_coder(server->host);
    }
    else
    {
        enet_host_compress(server->host, NULL);
    }
    rb_mutex_unlock(lock);
    return Qnil;
}
コード例 #5
0
void NetworkedMultiplayerENet::_setup_compressor() {

	switch(compression_mode) {

		case COMPRESS_NONE: {

			enet_host_compress(host,NULL);
		} break;
		case COMPRESS_RANGE_CODER: {
			enet_host_compress_with_range_coder(host);
		} break;
		case COMPRESS_FASTLZ:
		case COMPRESS_ZLIB: {

			enet_host_compress(host,&enet_compressor);
		} break;
	}
}
コード例 #6
0
ファイル: renet_connection.c プロジェクト: jvranish/rENet
VALUE renet_connection_use_compression(VALUE self, VALUE flag)
{
  Connection* connection;
  Data_Get_Struct(self, Connection, connection);
  VALUE lock = rb_iv_get(self, "@lock");
  rb_mutex_lock(lock);

  if (flag == Qtrue)
  {
    enet_host_compress_with_range_coder(connection->host);
  }
  else
  {
    enet_host_compress(connection->host, NULL);
  }

  rb_mutex_unlock(lock);
  return Qnil;
}
コード例 #7
0
ファイル: Network.cpp プロジェクト: tapio/Wendy
bool Host::init(const String& name, uint16 port, uint8 maxChannelCount)
{
  m_server = false;

  m_object = enet_host_create(nullptr, 1, maxChannelCount, 0, 0);
  if (!m_object)
  {
    logError("Failed to create ENet client host");
    return false;
  }

  if (enet_host_compress_with_range_coder((ENetHost*) m_object) < 0)
  {
    logError("Failed to create ENet range compressor");
    return false;
  }

  ENetAddress address;
  address.port = port;

  if (enet_address_set_host(&address, name.c_str()) < 0)
  {
    logError("Failed to resolve server name %s", name.c_str());
    return false;
  }

  ENetPeer* peer = enet_host_connect((ENetHost*) m_object,
                                     &address,
                                     ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT,
                                     0);
  if (!peer)
  {
    logError("Failed to connect to server %s:%u", name.c_str(), port);
    return false;
  }

  return true;
}
コード例 #8
0
ファイル: Network.cpp プロジェクト: tapio/Wendy
bool Host::init(uint16 port, size_t maxClientCount, uint8 maxChannelCount)
{
  m_server = true;

  ENetAddress address;
  address.host = ENET_HOST_ANY;
  address.port = port;

  m_object = enet_host_create(&address, maxClientCount, maxChannelCount, 0, 0);
  if (!m_object)
  {
    logError("Failed to create ENet server host");
    return false;
  }

  if (enet_host_compress_with_range_coder((ENetHost*) m_object) < 0)
  {
    logError("Failed to create ENet range compressor");
    return false;
  }

  return true;
}