Results 1 to 3 of 3

Thread: Is there any CL_NetGameConnection recv_event?

  1. #1

    Question Is there any CL_NetGameConnection recv_event?

    Hi,
    I'm programming a game, and have some problems with sending and receiving data.
    I have a trigger function on receiving data, so anytime server want to inform something it will call that function.
    Now I need to send an event to the server and receive the response immediately, not to wait until it will trigger the "on event" function because it will make problems with game logic.

    For example:

    PHP Code:
    Function X() {
       
    send_event(someEvent);
       
    //Here I need to get the immediate response to my request without triggering the "on event" function
       
    recv_event?

    a real exemple

    PHP Code:
    Function Add(nr1nr2) {
        
    //Ask Server to add 2 numbers
        
    CL_NetGameEvent ev("AddEvent");
        
    ev.add_argument(nr1);
        
    ev.add_argument(nr2);
        
    send_event(ev);
        
    //How to get the results?
        
    recv_event?


  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    There is no such function because the network communication is intentional asynchronous.

    When you send a message over the network there is no guarantee the receiver will ever reply. Blocking for a reply will also cause problems if it is a player in Europe and a server on the US west coast. That gives something like a 300 ms ping, which means that the game would drop to about 3 fps if you wait for a reply on each frame.

    If you are still absolutely certain you need to wait for a reply (i.e. when logging in), you can write your own block function (while (!not_received) { keep_alive() }). You can't avoid getting the message returned via the signal though.

  3. #3

    Exclamation

    Quote Originally Posted by Magnus Norddahl View Post
    There is no such function because the network communication is intentional asynchronous.

    When you send a message over the network there is no guarantee the receiver will ever reply. Blocking for a reply will also cause problems if it is a player in Europe and a server on the US west coast. That gives something like a 300 ms ping, which means that the game would drop to about 3 fps if you wait for a reply on each frame.

    If you are still absolutely certain you need to wait for a reply (i.e. when logging in), you can write your own block function (while (!not_received) { keep_alive() }). You can't avoid getting the message returned via the signal though.
    Ok, I'll implement a state machine then.
    Its a card game and don't require high fps.

    Thanks

Similar Threads

  1. CL_NetGameConnection disconnect patch
    By genail in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 03-20-2010, 02:16 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
  •