Search Unity

Third Party Photon LAN, no internet

Discussion in 'Multiplayer' started by Synaps3, Mar 16, 2019.

  1. Synaps3

    Synaps3

    Joined:
    Mar 31, 2014
    Posts:
    5
    I am trying to configure my game to work on LAN with no internet using photon. Is this possible?

    I built my game and ran the exe separately which should be making the server.
    Then when I run my game in unity, it just says ExcpetionOnReceive while connecting to 127.0.0.1

    I my settings file, I have the following:
    Self Hosted
    127.0.0.1
    5055
    Udp
    AppId [blank]

    Do I need appid even for a local server? If yes, then is there any unity networking package that will work completely offline?
    Or maybe if I have appid, it will work offline?

    Here is the code I am using:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Network : MonoBehaviour
    6. {
    7.  
    8.     // Use this for initialization
    9.     void Start ()
    10.     {
    11.         Connect ();
    12.     }
    13.  
    14.     void Connect()
    15.     {
    16.         PhotonNetwork.ConnectUsingSettings ("v001");
    17.     }
    18.  
    19.     void OnGUI()
    20.     {
    21.         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
    22.     }
    23.  
    24.     void OnJoinedLobby()
    25.     {
    26.         PhotonNetwork.JoinRoom ("BEAST");
    27.     }
    28.  
    29.     void OnPhotonRandomJoinFailed()
    30.     {
    31.         PhotonNetwork.CreateRoom ("BEAST");
    32.     }
    33.  
    34.     void OnJoinedRoom()
    35.     {
    36.         GUILayout.Label ("It WORKED!!!!!");
    37.     }
    38. }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    PUN does not support hosting the game within some client. You always need a dedicated Photon Server for the clients to connect to. There are various pros for this approach and some cons, of course. It's simply the way Photon works.

    Photon Bolt can host the game in a Unity instance but still, you need a Photon Server for matchmaking and potentially for relay. So it's not an alternative for pure local network (without internet connectivity).

    Hosting a Photon Server is simple. Also, configuring the PUN 2 client for your your own Photon Server isn't very hard.
     
    Kalkatos likes this.
  3. SplashFoxGames

    SplashFoxGames

    Joined:
    Oct 10, 2012
    Posts:
    53
    Using Photon Bolt Pro and having Photon Server running - will it be possible to have few players playing a game in LAN without ANY internet connection at any stage?
     
  4. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
    With Bolt PRO it should be possible even without the photon server (with it you can do direct connections).

    Please contact us through email to get the details, as Bolt PRO licenses are handled specifically for each use case.
     
  5. perick

    perick

    Joined:
    Jun 20, 2008
    Posts:
    235
  6. SplashFoxGames

    SplashFoxGames

    Joined:
    Oct 10, 2012
    Posts:
    53
    Thanks for the answer. I have a project that is long time in development and still in "prototype" mode, using Unity 5.6 and PUN and now there is a requirement to have it running "with" and "without" internet connection modes. So besides having possibility of "LAN only" I want to upgrade to latest Unity version and start using DOTS. And there is a problem that "Connected games" feature is "too fresh", and Bolt is too "old" and doesn't support it as far as I know : ) So i'm confused of what path to choose... : )
     
  7. braur

    braur

    Joined:
    Jan 7, 2018
    Posts:
    7
    Hi guys,

    I'm using the approach presented by @tobiass and it works, quite Ok.

    But there is one problem - I wanted to provide a functionality to switch between cloud / LAN on my clients in a run time:

    Switching to LAN:
    Code (CSharp):
    1. PhotonNetwork.PhotonServerSettings.AppSettings.Server = *my LAN IP*
    2. PhotonNetwork.PhotonServerSettings.AppSettings.Port = *my LAN port*
    3. PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "";
    4.  
    Switching to cloud
    Code (CSharp):
    1. PhotonNetwork.PhotonServerSettings.AppSettings.Server = null;
    2. PhotonNetwork.PhotonServerSettings.AppSettings.Port = 0;
    3. PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = *my fixed region*;
    And now where the problem happens:

    1. I start the app, by default the cloud mode is switched on, I connect to the cloud server successfully. I disconnect.
    2. I switch to LAN mode, I connect to the LAN server successfully. I disconnect.
    3. I switch back to the cloud mode and try to connect and receive an error: OperationResponse 230: ReturnCode: 32756 (). Parameters: {} Server: NameServer Address: *my LAN IP*:my LAN port*

    So... Despite the fact I did 'Switch to cloud' (code above) Photon somehow still tries to connect to my LAN IP address.

    Is there any way to "reset" the thing on runtime? Or maybe I'm missing something here?


    BR!
    Jacob
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    Do you disconnect before you connect again? Do you call ConnectUsingSettings()?