Author Topic: Can't get RFC working  (Read 2091 times)

BumpkinRich

  • Guest
Can't get RFC working
« on: November 09, 2013, 05:35:33 PM »
Hi,

I'm working on a peer to peer implementation but I can't get a RFC working.

Server connection -
//Create server
TNServerInstance.Start(port);

//Connect
TNManager.Connect("127.0.0.1", port);

Client connection -

//Connect to server
TNManager.Connect("127.0.0.1", port);


On the OnNetworkConnect method I check for success and call TNManager.JoinChannel(123, "TestScene");

Test scene loads and I have the following code attached to a game object to test a simple message.

  1. using UnityEngine;
  2. using System.Collections;
  3. using TNet;
  4.  
  5. public class TNetWaitingArea : MonoBehaviour {
  6.  
  7.     private string text = "text";
  8.     private string enterText = "message";
  9.  
  10.     void OnGUI()
  11.     {
  12.         GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
  13.         GUILayout.Label(TNServerInstance.playerCount.ToString());
  14.         GUILayout.Label(text);
  15.         enterText = GUILayout.TextArea(enterText);
  16.  
  17.         if (GUILayout.Button("Test"))
  18.         {
  19.             Debug.Log("Calling");
  20.             TNObject tbo = GetComponent(typeof(TNObject)) as TNObject;
  21.             tbo.Send("TestMessage", Target.All, enterText);
  22.         }
  23.  
  24.         GUILayout.EndArea();
  25.     }
  26.  
  27.  
  28.     [RFC] void TestMessage(string msg)
  29.     {
  30.         Debug.Log("Test called");
  31.         text = msg;
  32.     }
  33. }
  34.  

I can see that there are player connected on the server, I am getting no error messages but the TestMessage method is never called.  Not even locally. 

Been looking at this for a few hours now, pouring over the forums and code but getting nowhere fast.  My guess is that I'm missunderstanding something fundamental like channels, or maybe I shouldn't be connecting to the server like a client in the same instance?

Any help greatfully received.

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Can't get RFC working
« Reply #1 on: November 09, 2013, 05:57:22 PM »
I just solved similiar problem myself, if the "gameObject" is in the scene from the begining(not instantiated by tnManager) so should you preset and ID for the tnObject, example 10

BumpkinRich

  • Guest
Re: Can't get RFC working
« Reply #2 on: November 10, 2013, 04:02:30 AM »
Changed the Id of the TNObject to 1 and it got an error saying it couldn't find the TestMessage method.

A look around and I found that if your not inheriting from TNBehaviour you have to get the TNObject to rebuild its method list using tno.rebuildMethodList = true;

Now it's working  :)

Cheers addebooi!