Problem sending over more than one channel on enet.

Started by
2 comments, last by graveyard filla 19 years, 3 months ago
I can send on channel 0 but when I try channel 1 it isnt recived.

void MainWindow::SendToClient( char *data, long length, int index, int channel, int flag )
{
   // Create a packet of size lenght containing data
   ENetPacket * packet = enet_packet_create( data, 
                                             length, 
                                             flag );
    
    // Send the packet to the peer over channel id channel. 
    // One could also broadcast the packet by         
    // enet_host_broadcast( m_Server, channel, packet );
    enet_peer_send( &m_Server->peers[index], channel, packet );

    // One could just use enet_host_service() instead. 
    enet_host_flush( m_Server );
}

void MainWindow::CreateClient()
{
   m_Client = enet_host_create( NULL, // create a client host
                                ENET_CHANNEL_SIZE-1,    // Is this is for peers, or channels?
                                57600 / 8,   // 56K modem with 56 Kbps downstream bandwidth
                                14400 / 8 ); // 56K modem with 14 Kbps upstream bandwidth 

   if( m_Client == NULL )
   {
      m_Mutex.Lock();
      m_Console.AddLine( "An error occurred while trying to create an ENet client host." );
      m_Mutex.Release();
   }
   else
   {
      m_Mutex.Lock();
      m_Console.AddLine( "An enet client was successfully created." );
      m_Mutex.Release();
   }
}

      // network channels
      enum 
      {
         ENET_CHANNEL_TEXT = 0,
         ENET_CHANNEL_COMMAND,
         ENET_CHANNEL_POSITION,
         ENET_CHANNEL_SIZE,
      };

      enum 
      {
         COMMAND_START = 1,
         COMMAND_NEW_ROUND,
      };


Try to send like this: SendToClient( (char*)&command, sizeof(command), 0, ENET_CHANNEL_COMMAND, ENET_PACKET_FLAG_RELIABLE ); If I dont figuer why this isnt working I will have to make my own packet class which adds alot of overhead to what enet does already.
Advertisement
are you sure your specifying the right number of channels when connecting? i believe the parameter is in the call to enet_host_connect(). make sure you specified enough channels here.
FTA, my 2D futuristic action MMORPG
thanks gfilla:

My online pacman clone is one step closer to completion.
btw, if you like eNet, you might really love RakNet. i switched over from eNet to RakNEt towards the end of my online pong clone and never looked back. it has a much more elegant system and better docs and support. nothing against enet though, its a nice lib as well, but its hard to find answers to questions you might have, and its not as high level as i like. also, you wouldnt need to use threads with it. why are you using threads anyway? eNet doesnt really require them, except maybe for connecting.

anyway, good luck.
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement