Results 1 to 4 of 4

Thread: Sending an array with NetGame

  1. #1

    Default Sending an array with NetGame

    Hello,
    The project I am currently working on in ClanLib requires me to send an array of ints through the network, and I was wondering what the best way to do this was.
    The array is 72x72 in size, so that's 5184 elements, all of which are required to be sent. Although currently all the values take up less than a byte, so I did try putting it into a char array and sending that, but that didn't work so well. maybe because some of the values are 0, but I think there's more ro it than that.

    So, what is the best way to send an array in NetGame?

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    What I do myself is to send an integer telling how many items in the array, and then adding each item.

    Here is an example from my own code serverside:

    Code:
    CL_NetGameEvent event(STC_OBJECT_COMPONENT_REQS);
    
    event.add_argument(clientComponentRequirements.size());
    for(size_t i = 0; i < clientComponentRequirements.size(); ++i)
        event.add_argument(clientComponentRequirements[i]);
    
    SendEvent(event, playerConnection);
    And on the client side:

    Code:
        unsigned int componentRequirementCount = e.get_argument(argumentIndex++);
        for(unsigned int i = 0; i < componentRequirementCount; ++i)
        {
            CL_String componentRequirement = e.get_argument(argumentIndex++);
    
            AddComponent(componentRequirement);
        }
    You could also calculate the size of the array instead of sending the first integer by using event.get_argument_count().

  3. #3

    Default

    Thankyou, I'll try that.

    One more thing, what is the best way to get the server to drop a client?
    Currently I have the server sending an event to the client, then the client disconnecting, but I would prefer it if the server could disconnect the client.
    Blep is superior to all other terms and concepts.

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Seems client disconnection functionality is not exposed in the netgame api yet...

Similar Threads

  1. questions about netgame event value
    By ppheathead in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-07-2009, 07:10 AM
  2. problem of raw data parameter passing netgame engine
    By ppheathead in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 07-06-2009, 12:11 PM
  3. NetGame channeling?
    By catch22 in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 05-29-2009, 06:43 AM
  4. Sending message to server
    By croland in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 12-24-2006, 03:56 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •