Author Topic: Beginner with networks needs some help!  (Read 4606 times)

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Beginner with networks needs some help!
« on: March 07, 2013, 01:49:21 PM »
Hi! TNet is something i think it will be very useful as NGUI was to me! But being a beginner in networking i am struggling like i once was with NGUI. But i think when i get a handle of it will be easy to get things done.

I was going through examples and i played with them a bit, the most useful situation for me is the fact that it is possible to create a server on mobile device and let others connect. I doubt that i will use standalone server for now, its good to know that is possible too.

So i have a few questions
1.) in the example menu you used Update() to get the list of available servers. Is there and event that fires when servers are available? I would avoid using Update (i could use coroutines to periodically check for servers though, but event would be great), how to broadcast to everybody on lan that there is new server started
2.) i do not understand how to distinguish between the client and host. if one player starts the server, is his device a host? and is there a difference how host connects to server from client? is that the reason why there are few types of TNManager.Connect methods?
3.) when we should be using udp and when tcp? do we need to start to StartUDP at the beginning?

these are my questions for now! i am sorry that most of them are beginner questions, but a lot of new info is there that i have to process :D

Thank you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Beginner with networks needs some help!
« Reply #1 on: March 07, 2013, 04:06:56 PM »
1. UDP client receives packets in the update, but you don't have to worry about it. Set TNLobbyClient's onChange delegate, and it will be called when the list of servers changes.

2. Server is whom you connect to. Think of it as an IRC server. It lets others connect, but you can't talk as the server. You have to connect as a client to this server before you can talk with others. The first person to join a channel is automatically given the "ops" status in IRC (moderator) -- which is identical to the "host" status in TNet. When the host leaves, another host is chosen automatically behind the scenes.

3. Yes you need to call TNManager.StartUDP() if you plan on sending or receiving UDP packets. Frequently sent packets that you can afford to lose such as position updates should be sent via UDP.

tehshawn

  • Guest
Re: Beginner with networks needs some help!
« Reply #2 on: March 07, 2013, 10:01:44 PM »
ArenMook, do you think people will interpret the term "Host" to mean that that person is the server instead of something like an op?

If you take the perspective of someone new, there is quite a lot going on compared to what someone might expect.
So if they simply expect: Servers and Clients
TNet actually provides: Lobby Servers, Lobby Clients, Servers, Clients, Channels, and said "Hosts"

I feel like this particular term might be a stumbling block for those trying to understand the package. Perhaps a term like "moderator", "chief", etc may be more apparent so as not to get confused with which entity is the real server. Either way, looking forward to your enhancements in the next version.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: Beginner with networks needs some help!
« Reply #3 on: March 07, 2013, 11:55:18 PM »
ArenMook, do you think people will interpret the term "Host" to mean that that person is the server instead of something like an op?

If you take the perspective of someone new, there is quite a lot going on compared to what someone might expect.
So if they simply expect: Servers and Clients
TNet actually provides: Lobby Servers, Lobby Clients, Servers, Clients, Channels, and said "Hosts"

I feel like this particular term might be a stumbling block for those trying to understand the package. Perhaps a term like "moderator", "chief", etc may be more apparent so as not to get confused with which entity is the real server. Either way, looking forward to your enhancements in the next version.

Here's how I understand these terms with regard to TNet:

Server: This is the actual backend server that manages communication between all the clients. All clients (including the person who will be the host) connect to the server.
Client: Anyone who connects to the server. The host is also a client.
Host: The client who is hosting the current channel (instance). Think of him like a party leader, or the person in charge, or whatever. He's just the guy who joined first or set up the game (depending on how your game works). Note that the host could also be running the server, but isn't necessarily. The Host is also a client, but good practice for TNet is to make the host the authority on the game, make all the decisions, run all the simulations, etc., and then send the results to the other clients using the server.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Beginner with networks needs some help!
« Reply #4 on: March 08, 2013, 04:00:45 AM »
That's a great explanation, Deozaan.

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: Beginner with networks needs some help!
« Reply #5 on: March 08, 2013, 06:09:47 AM »
Thanks for explanation!

I tried what you suggested and i am now refreshing the list of servers with TNLobbyClient.onChange += ServerListRefresh;
and this works very well, but i was under impression that onChange event is fired only when list changes a new server is added, but the event fires every few seconds even if i started just one server (is this intended?)

Now, i managed to start server,connect and join the channel. Other players are able to connect and join the channel, i understand relationships server/host/client and that is clear.

I am getting the exception for OnNetworkPlayerLeave when player who is hosting leaves the channel. I dont know how to handle this.

Thanks for help, i will post here if there is something i could not get to work by myself!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Beginner with networks needs some help!
« Reply #6 on: March 08, 2013, 07:06:11 PM »
In case of UDP there is no connection, so the list is queried every so often, which is why you see it get updated.