Connecting to Lan

Does anyone know how to connect to a Lan session?

I know you have to call BoltNetwork.EnableLanBroadcast(); but then what, how does the client connect to it?

The UdpSession still returns UdpSessionSource.Photon and not UdpSessionSource.Lan

I have search the internet and there's no tutorials and the documentation doesn't say much either.

Comments

  • ramonmelo
    ramonmelo mod
    edited May 2019
    Hello,

    If you are using Bolt Free, you are always creating a Photon session.

    The EnableLanBroadcast will just decrease the time to your client receive the session, or if you are creating an invisible session, making the session available only locally.

    So, you will still need to be connected to the Photon Cloud and the connection process will be exactly the same as if the client received that session information from the cloud server.

    Some notes about this type of session:
    1. Even if the session is broadcasted via LAN, the connection between the peers are not guaranteed via punch, for several reasons;
    2. It's in some way better than the usual LAN session, as both local and remote players can play the same game.
  • @ramonmelo thanks for the reply.

    I am using the code provided in the documentation, if i had BoltNetwork.EnableLanBroadcast(); right after
    BoltLauncher.StartServer(); it connects to Lan automatically?

    And the photonSession.Source == UdpSessionSource.Photon in SessionListUpdated always returns Photon not Lan so i am not really sure what is going on.
    public class Menu : Bolt.GlobalEventListener
    {
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));
    
            if (GUILayout.Button("Start Server", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                // START SERVER
                BoltLauncher.StartServer();
            }
    
            if (GUILayout.Button("Start Client", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
            {
                // START CLIENT
                BoltLauncher.StartClient();
            }
    
            GUILayout.EndArea();
        }
    
        public override void BoltStartDone()
        {
            if (BoltNetwork.isServer)
            {
                string matchName = Guid.NewGuid().ToString();
    
                BoltNetwork.SetServerInfo(matchName, null);
                BoltNetwork.LoadScene("Tutorial1");
            }
        }
    
        public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
        {
            Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count);
    
            foreach (var session in sessionList)
            {
                UdpSession photonSession = session.Value as UdpSession;
    
                if (photonSession.Source == UdpSessionSource.Photon)
                {
                    BoltNetwork.Connect(photonSession);
                }
            }
        }
    }
  • @Psycocrusher

    If you are using Bolt Free, all session that you creates or joins are of Photon Type, always.

    When you EnableLanBroadcast on the game host, you are just instructing Bolt to also advertise this session via a LAN, so any other peer that is listening on the broadcast IP (by calling `EnableLanBroadcast` on the client too) will receive this session. This is not a LAN session, it's just broadcasted on the local network.

    This feature is a shortcut, instead of receiving the session by listening updates from the Photon Cloud, you will also receive session updates from the local network. In both cases, the session is the same, a Photon session.

    About your question, no, when you enable the LAN broadcast, you will not connect automatically by default. This will occurs only if you want, like it's shown on the snippet, in which the peer will connect to the first Photon session found.