1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Client <-> server communication... again...

Discussion in 'Programming' started by lazy303, Sep 27, 2004.

  1. lazy303

    lazy303 New Member

    Joined:
    Sep 20, 2004
    Messages:
    13
    Likes Received:
    0
    I have an Interaction class (on the client) which in the PostRender function calls a function on the server. The server function is supposed to return a bool. The client allways gets a false even if I return true from the server.
    I guess the client doesn't wait for the server to respond so it will
    allways be false.
    Am I right about that? Is there some good solution?

    /lazy
     
  2. Mychaeel

    Mychaeel New Member

    Joined:
    Oct 3, 2001
    Messages:
    3,830
    Likes Received:
    0
    Replicated functions are called asynchronously and thus can never return anything. Just imagine what'd happen to the client's frame rate if the client had to wait for a server response on each frame...
     
  3. Kamek

    Kamek Magikoopa

    Joined:
    Sep 26, 2004
    Messages:
    10
    Likes Received:
    0
    Try something like this.

    Code:
    class NewInteraction extends Interaction;
    
    var bool bReturnProperty;
    
    replication
    {
    	// Stuff the server needs to send to the client
    	unreliable if (Role == ROLE_Authority && bNetDirty)
    		bReturnProperty;
    
    	// Stuff the client must send to the server
    	unreliable if (Role < ROLE_Authority)
    		CallServerFunction;
    }
    
    function bool ReturnABool()
    {
    	// Stuff you needed to do server-side goes here.
    	return SomeBooleanValue;
    }
    
    function CallServerFunction()
    {
    	// This calls the function on the server and stores the return value in
    	// bReturnProperty.
    	if (Role = ROLE_Authority)
    		bReturnProperty = ReturnABool();
    }
    
    simulated function PostRender(canvas Canvas)
    {
    	if (Level.NetMode != NM_DedicatedServer)
    	{
    		// Your code goes here
    		CallServerFunction();
    	}
    	// Whenever the server gets done processing whatever it is you needed
    	// on the client, bReturnProperty will be set. For now, continue
    	// processing code as though bReturnProperty was set.
    }
    
    The function call will pass to the server for each PostRender, but since it's unreliable it will only be executed if bandwidth is available, and the server will return the value in bReturnProperty whenever bandwidth is available. Until the server replicates that bReturnProperty, PostRender just uses whatever value was there before.

    Hope this helps some..
     

Share This Page