Author Topic: Joining channel on local network  (Read 6469 times)

larryapple

  • Guest
Joining channel on local network
« on: February 24, 2013, 03:21:31 PM »
First let me say that I am a long-time C++ and then Objective-C programmer, and I greatly appreciate the way you structure your code. I tried out Photon and also took a long look at the uLink documentation, and did not like the way they were designed or their unreliability.

For the past week I have been studying TNet and trying out the examples, reading all of the documentation, etc. So far I have been unable to connect two instances of my game on my local Mac network and print out the list of players to show more than one player. That is the only code I have added so far, as a separate game object with the TNObject, TNManager, and a very short ClientHookup script added. No changes to any other code yet. Because of an unrelated (audio) issue, I am running only one client on my Mac, and the other clients on either IOS and Android.

For my latest tests I created a new project with release 1.5, included all of the Example code and built it as a Unity file for Mac & PC. It works perfectly on my Mac. I can run this separately and start the local server. Or I can start the server in my Client Hookup script:

using UnityEngine;
using System.Collections;
using TNet;

public class ClientHookup : MonoBehaviour
{

   string mAddress = "127.0.0.1:5127";
//   string mAddress = "67.161.180.91:5127"; // this is the address that shows in the example server list
   string mMessage = "";

   void Start ()
   {
      if (Application.isPlaying)
      {
         // We don't want mobile devices to dim their screen and go to sleep while the app is running
         Screen.sleepTimeout = SleepTimeout.NeverSleep;
      }
//      TNServerInstance.Start (5127);
      TNManager.Connect(mAddress);
      mMessage = "Connecting...";
   }
   
   void OnNetworkConnect (bool success, string message)
   {
      if (message != null)
      {
         mMessage = message;
         print (message);
      }
      
      TNManager.JoinChannel (17, "CribApple");
      
//      print (TNManager.players);
      
      
      List <Player> players = new List<Player> ();
      for (int i = 0; i < TNManager.players.size; i++)
         players.Add (TNManager.players );
         
      print (players);
   }
}

I used channel 17 so as not to conflict witht the four examples.

No matter what I do, it only prints out one player.

Regards,
Larry Applegate






ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Joining channel on local network
« Reply #1 on: February 24, 2013, 04:57:32 PM »
127.0.0.1 is a loopback address. It always points to the machine where you are executing the command. This will be the address of your mac when you run it on the mac, or the address of your android when you run it there. You need to specify an actual valid address to connect to for it to work from another machine. To determine your local IP address (usually 192.168.x.x), run the Network Utility.

P.S. There is no reason to start the server on every device. Only one needs to run the server -- others should connect to that server.

tehshawn

  • Guest
Re: Joining channel on local network
« Reply #2 on: February 24, 2013, 05:18:22 PM »
Also you probably want to wait until a success notification in a "OnNetworkJoinChannel" method before checking for other network players.

larryapple

  • Guest
Re: Joining channel on local network
« Reply #3 on: February 24, 2013, 09:27:12 PM »
Thank you both for the explanations! I was confused why the example server startup shows 67.161.180.91(.5127) whereas the network shows 10.0.1.6. I presume the other ip address is my external IP? And that my development partner could reach me there?

I was also confused that printing the List array in the console did not show any list items or count, where the debugger does. Sorry, I am new to C# but am already really liking it better than Objective-C, with its mixture of 3 kinds of methods when you throw in Core Foundation and straight C callbacks. Unity removes so much of all that hassle.

I was also having difficulty because Unity mangles my 147 mp3 audio files by changing them to OOG if I build for MacOS, and adding almost a second of silence to each file. So I had to test on multiple platforms, which made things more confusing. Now I have bit the bullet and am using low-res WAV files, at least for development.

So thanks again, I can now start creating the 2-player version of my cribbage game's opponent play. This way the player code won't have to know whether it is playing the computer or a real opponent, and that will be so cool.

Regards,
Larry

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Joining channel on local network
« Reply #4 on: February 25, 2013, 06:25:42 AM »
MP3 file format has the silence, not the OGG. If you save all your original files as OGG, you won't have any silence.

TNet uses two addresses -- internal and external. 10.0.1.6 is your internal one, 67.x.x.x is your external one -- so yes, people will be able to join your server using the external address.

larryapple

  • Guest
Re: Joining channel on local network
« Reply #5 on: February 25, 2013, 11:51:12 AM »
I wondered why the mp3 files showed the silence, which was automatically removed on playback in IOS and Android, and not on MacOS. This is very good news! What a difference your knowledge makes.

If I understand correctly, I will be able to export two versions of the files (using Export using Range Markers from Adobe Audition), OGG for Mac/PC and MP3 for IOS/Android. The MP3 versions are marked as Decompress on load, no 3D, and Use Hardware Decoding. They play back correctly without the silence on both IOS and Android, even though the silence shows in the Unity Inspector. The OGG files do not show the silence, and therefore also will play back correctly. What setting for load type should I use in Unity to make sure that playback will not be delayed, thus destroying the continuity of my connected words and phrases? I would guess Decompress on Load.

There is another annoyance with Unity audio, after importing my audio files I must change all the settings one at a time. And soon I will have another voice recorded, which will even double that work again. Do you know of a workaround or tool to avoid this?

Thanks again,
Larry



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Joining channel on local network
« Reply #6 on: February 25, 2013, 05:53:50 PM »
I recommend not using MP3s at all. Just OGG.

larryapple

  • Guest
Re: Joining channel on local network
« Reply #7 on: February 26, 2013, 02:28:09 AM »
Thanks, I will. I wasn't too happy about that extra silence, even if it mostly didn't play.