Author Topic: TNet: Tasharen Networking Framework  (Read 117390 times)

danreid70

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #150 on: January 23, 2013, 07:17:14 PM »
Hi Aren - I love your NGUI (purchased it a few months back, and only now getting to it - kind of a spare time project I'm working on for fun). I really want to (and will) purchase TNet - after reading the forums here and on Unity Forums, TNet sounds PERFECT for my game.

What are the chances you could put a sample in the TNet package, with a character controller - and a very simple connect/choose-lobby/choose-level/launch-level-with-synced-character-controller menu, using NGUI? That's the part I keep getting stuck on. Just something very simplistic.

The reason I ask, is I keep thinking I have the right structure with NGUI, but then I look back at your examples and I keep redoing basic parts as I see how clean you did them in your samples. Your setups are very clean, and I'd like to try and follow that same example with TNet using the NGUI menu. Or do you already have a sample like this in the package?

I'm currently using a very spaghetti-coded Unity networking solution, that I'm wanting to scrap and just start all over with - which is why I started looking at TNet...

Thanks already for NGUI, and keep up the great work with TNet! I'll be purchasing VERY soon!
--Dan
« Last Edit: January 23, 2013, 07:19:57 PM by danreid70 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #151 on: January 23, 2013, 07:27:16 PM »
@enzi: Network.time is actually really unreliable in Unity. I know from personal experience -_-. I've seen over a second difference playing locally (!) in some cases. TNManager has a "ping" parameter that you can use, but there is no concept of "network time" in TNet. What do you need it for anyhow?

@danreid70: There is no character controller example with TNet. It's really simple to do though. In OnNetworkJoinChannel, TNManager.Create your player, and in a script attached to the player check -- TNManager.isThisMyObject? If so, control it. Otherwise let someone else control it.


enzi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #152 on: January 23, 2013, 08:15:18 PM »
I got it working. Thanks to the setup it's a breeze to put in new responses and requests.

But unfortunately I was on the wrong track. I thought my position interpolation got out of sync due to wrong timestamps from the server and the client. I'm using DateTime.Now.ticks. But that was never the issue to begin with.

For some reason the character controller on the server moves at a slightly higher speed. It's probably a totally stupid bug but I've checked nearly everything (is the fixed timestep correct, calculating the actual speed of the server/client) and from the data I gathered everything SHOULD be fine but it's not. I understand latency but not why the damn server character always outruns my client character. Makes no sense.

Oh well, I'll just sleep over it. That always helps. ^^

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #153 on: January 24, 2013, 09:28:54 AM »
Check the framerate. More often than not such things are caused by forgetting to take Time.deltaTime into account in your Update functions.

enzi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #154 on: January 24, 2013, 10:29:30 AM »
I do all my movement calculations in FixedUpdate with a timestep of 20ms. It's crude as I don't have any complex accelerations and stuff in it. It's running with the same speed locally but not on the server.

I've to dig deeper. :)

zyeurgh

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #155 on: January 24, 2013, 07:18:21 PM »
Hi guys,

TNet has proven quite cool to use so far, good job on that :)

Now, I was trying to implement an entity interpolation solution for my game based on this:
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

It looks like it's quite dependent on clients/server having the same time, to allow to draw other players "in the past".
So I guess that rejoins the question that enzi had about the equivalent of Unity's NetworkMessageInfo.timestamp.
Since there is no notion of network time in tnet, I'll probably have a look at syncing time with the different clients too, using the ping maybe.
Or would you recommend another technique for players interpolation in a fps kind of game?

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #156 on: January 24, 2013, 09:05:12 PM »
When a new player joins the channel, host can send that player Time.realTimeSinceStartup. Add ping to that, and you will have a network time (as approximate as Unity's approach gets anyhow).

zyeurgh

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #157 on: January 25, 2013, 10:44:21 AM »
Thanks, I'll give that a go.

enzi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #158 on: January 25, 2013, 12:39:20 PM »
Zyeurgh, if you are working with DateTime.Now, keep in mind that it can be different on each client. You also have to sync this. I had to do this. But for overall timing I'm using simulation duration now instead of timestamps. The are annoying to work with because they are so inaccurate. So don't use them if you really need exact timings.

sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #159 on: January 25, 2013, 04:22:24 PM »
I have a turn-based card game that I want to implement networking on. This package seems to do what I want but I have a few questions.

My game design uses a client game manager object to update the GUI(NGUI, that is ;) )/gameobjects on screen and a "server" object that runs all the game logic with AI, etc. Originally, for Multi-player online, I was going to have a server computer run an instance of each "room" and disable the client game manager and screen GUI/gameobjects and just run the "server" game object using UDP messaging to/from the clients in the same room.  That may start to tax the resources of the server too quickly when I ramp up usage and have too many instances of a gameserver running on the server computer.

I like the idea of using a host player with token-passing capability if host connection is dropped, but:
 
  • If the host player drops, how does the alternate host player get the sate of all my internal variables, generic lists, etc. that I was using in the "server" game object? (There's about 80-90 of them)
  • I read about some AutoSync function. Can that be applied to a groups of internals I mentioned above? Is there example code of its usage?
  • Would each player be updating these states constantly so that when alternate host is ativated, it has accurate data?

Basically I want to make sure all "server" object states get accurately synced to all players who may become alternate hosts.

Which method would be best to use?

Thank you and I'm very excited about using this framework!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #160 on: January 25, 2013, 10:18:00 PM »
1. All clients should always be sync'd. When you do a Send to all, everyone gets the packet. The TNManager.isHosting client should be the only one to send out AI updates, however. You need to think less dungeon master, more group leader.

2. AutoSync can be used so automatically synchronize a public variable or property across all clients. Just attach the script to an object, and choose it from the drop-down list. If you need a tutorial for this, then something is really wrong. :)

3. Only the host should be sending out updates, as I mentioned in #1. But yes, all clients should be receiving them.

Based on your questions, I highly recommend you familiarize yourself with the examples in TNet before going further. You're approaching it from a traditional "server knows everything" perspective, when in TNet a server is simply there to forward packets between clients, and the authoritative player is the one that does all logic. It's a much cleaner design, and once you wrap your head around to it, you will be able to reduce your code paths significantly.

Zaibach333

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #161 on: January 26, 2013, 08:01:02 AM »
I'm running into a couple things with my game's server and TNet.

I used mostly the menu example code for starting the server but I run into this error:
Quote
NullReferenceException: Object reference not set to an instance of an object
TNet.UdpProtocol.Broadcast (TNet.Buffer buffer, Int32 port) (at Assets/TNet/Common/TNUdpProtocol.cs:199)
TNet.GameClient.EndSend (Int32 port) (at Assets/TNet/Client/TNGameClient.cs:348)
TNManager.EndSend (Int32 port) (at Assets/TNet/Client/TNManager.cs:484)
TNDiscoveryClient.RequestUpdate () (at Assets/TNet/Client/TNDiscoveryClient.cs:105)
TNDiscoveryClient+<PeriodicRequest>c__Iterator2.MoveNext () (at Assets/TNet/Client/TNDiscoveryClient.cs:89)

So I commented out all the UDP and TNDiscoveryClient I had in my script and it ran fine for a while but now I'm getting this error:
Quote
Exception has been thrown by the target of an invocation.
GameManager.RequestFinishDeployment ()
UnityEngine.Debug:LogError

(Object)
TNObject:Execute(Byte, Object[]) (at

Assets/TNet/Client/TNObject.cs:250)
TNObject:FindAndExecute(UInt32,

Byte, Object[]) (at Assets/TNet/Client/TNObject.cs:320)
TNObject:SendRFC(UInt32, Byte, String, Target, Boolean, Object[])

(at Assets/TNet/Client/TNObject.cs:499)
TNObject:Send(Byte, Target,

Object[]) (at Assets/TNet/Client/TNObject.cs:402)
GameManager:DrawDeploymentButton() (at

Assets/Paul_assets/scripts/Game/GameManager.cs:245)
GameManager:OnGUI() (at

Assets/Paul_assets/scripts/Game/GameManager.cs:173)

What's weird about that last one is it only seems to happen when I stop then start the server again. *I apologize in advance if this is another dumb question.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #162 on: January 26, 2013, 07:54:33 PM »
Your error log points to a problem in GameManager.RequestFinishDeployment function, which is game code, not TNet.

Zaibach333

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #163 on: January 27, 2013, 12:19:59 AM »
this is GameManager.RequestFinishDeployment :

  1. [RFC(12)] void RequestFinishDeployment() {
  2.         if (TNManager.isHosting) {     
  3.                 tno.Send(14, Target.AllSaved);
  4.         }
  5. }

and 14 exists too:
  1. [RFC(14)] void SetToTurnSequence() {
  2.         deployment = false;
  3.         movement = true;
  4. }

is there a limit to the amount of RFC calls?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #164 on: January 27, 2013, 12:37:52 AM »
You don't have to specify an ID for RFCs. IDs are only useful if you are trying to optimize bandwidth usage. You can have up to 255 unique IDs on the same TNObject.

P.S. Make sure your RFC ID (14) is not used on another script on the same TNObject, or you will have weird issues. Also... is there a reason why you do what you do? RequestFinishDeployment only does something on the host... so why not just set the 12's call to be Target.Host, and not do this?
« Last Edit: January 27, 2013, 02:29:39 AM by ArenMook »