Author Topic: Sending RFCs/packets from one TNObject to a different TNObject  (Read 6781 times)

krissebesta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Sending RFCs/packets from one TNObject to a different TNObject
« on: February 11, 2013, 08:29:47 AM »
Hello!  Still learning how to use TNet.  Can I use TNObject A's Send() to call an RFC that is defined in TNObject B?  Where objects A and B are totally different objects/classes (not just different instances).

I have a simple server and client (separate Unity projects/apps) created.  I want the client to call a RFC on the server, however, the server does not have the object that the client has (TNObject A for example) but it does have the RFC function in a different TNObject.  So, the server only has TNObject B, which is a totally different object.  Could TNObject B (on the server) have an RFC function that gets called by the client from TNObject A?

Or do I need to define a new packet type in TNPackets.cs and build a custom packet (BeginSend and EndSend)?  Is there another way to build a custom packet without modifying TNPackets.cs?  Do you have an example of this?

Thanks!
« Last Edit: February 11, 2013, 08:32:24 AM by krissebesta »

sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #1 on: February 11, 2013, 12:45:56 PM »
Not to step on ArenMook's toes, but I had success doing exactly what you described, by setting the Object A and B TNObject IDs to the same number (even though Object A and B are GameObjects with different Components). Once I did that, I could then call RFC functions from either object's methods using the Send command.

I'm not sure if this is intentional but it worked for me!

 ;D

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #2 on: February 12, 2013, 09:20:53 AM »
If you want to call a remote object's function, create an RFC either on that object, or have one RFC simply call a function somewhere else. You should not duplicate object IDs. It's curious that it worked for sunriser, but it's not intentional nor officially supported. :)

sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #3 on: February 12, 2013, 12:29:42 PM »
I have yet to be able to accomplish this with the scenario first described by krissebesta.

Here's my usage:

Object A has a TNObject (id =21) and has a scr_Server Component which contains this method:

 
  1. public string SendToClient(bool RemoteFlag, string clientID, string QueryType, string MessageString, bool AsyncFlag)
  2.     {
  3.              
  4.         tno.Send("MessageFromServer", TNet.Target.Others, MessageString, AsyncFlag);
  5.        
  6.     }

Object B has a TNObject (id =22) and has a scr_Client_Game_Managerr Component which contains this method:

  1. [TNet.RFC]
  2.     public void MessageFromServer(string TNetMessage, bool AsyncFlag)//ONLINE ONLY
  3.     {
  4.         NGUIDebug.Log(TNetMessage);      
  5.     }

With Object A and B set to different TNObject Ids = no worky  :(

If I change Object A to Id 22 to match Object B = worky!  :)

One important thing to note: These objects are on two different scenes running in two different instances of the game (server.exe and client.exe) Not sure if that makes a difference...

Am I missing something here?
« Last Edit: February 12, 2013, 12:33:43 PM by sunriser »

krissebesta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #4 on: February 12, 2013, 10:16:18 PM »
Hey Sunriser, question for you.  How did you get the client and the server to load different scenes?  It was my understanding that when you call JoinChannel() with the scene name it basically forces any clients that join to load the same scene.  Did you override this?  If so how?  Can you post a code example on how you did this?

Thanks! - Kris

sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #5 on: February 13, 2013, 11:27:35 AM »
If you want to call a remote object's function, create an RFC either on that object, or have one RFC simply call a function somewhere else. You should not duplicate object IDs. It's curious that it worked for sunriser, but it's not intentional nor officially supported. :)

I think it works because I'm running the TNObjects in seperate scenes in separate executables (a client version of the game and server version)

It's like your examples: If I load up several Example exes, all the clients will use the same Object ID for each of its TNObjects, right?


sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #6 on: February 13, 2013, 11:38:40 AM »
@krissebesta:

I have tried unsuccessfully to post a response to your questions but the forum keeps giving me a Forbidden response.

Send me a private message with an email address and I'll send it that way.

 :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sending RFCs/packets from one TNObject to a different TNObject
« Reply #7 on: February 13, 2013, 01:29:35 PM »
When you get a "forbidden" response, make a simple reply then edit it out with the real information. The forum is... questionable sometimes.