Author Topic: Best way to handle automatic connection setup?  (Read 3139 times)

0xFEEDBEEF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Best way to handle automatic connection setup?
« on: May 14, 2015, 02:31:25 PM »
Here's my use case:

-I have a number of portable devices (1 to 4). They will always be on the same network (as all of them will always be in the same room)

-Server/client setup needs to be silent and automatic, with no need to press buttons or enter IPs. Therefore, I'd like each device to be able to automatically connect to the first server it detects on the same network, or if no server is detected, start one up and inform the other devices that it exists.

What's the best/proper way to handle this with TNet?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to handle automatic connection setup?
« Reply #1 on: May 14, 2015, 06:34:32 PM »
Do LAN-based server discovery like in the TNet example. If no servers respond after X seconds, have one client start one.

0xFEEDBEEF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Best way to handle automatic connection setup?
« Reply #2 on: May 14, 2015, 11:55:57 PM »
Thanks! That gives me someplace to start.

I'm experimenting with TNObject.BroadcastToLAN() at the moment. Have you ever run into a situation where it works perfectly in the Unity editor, but nothing happens in a build?

I'm running Unity 4.6.5.f1 on OS X Yosemite, and built both a Mac app and a Windows executable. I've tested the builds on a Windows 8.1 machine and the iMac with identical results.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to handle automatic connection setup?
« Reply #3 on: May 22, 2015, 05:38:03 PM »
As I recall OSX's broadcast is different... in one case it's a broadcast, in another a multicast unless you explicitly set it to something. Check UdpProtocol.useMulticasting