[SOLVED] I can't connect to my Photon server (self hosted).

Artoliz
Artoliz
edited September 2020 in Photon Server
Hello,

After a little hour of searching for a similar post (please excuse me in advance if I didn't find one and you redirect me to a similar post...), I can't find a solution to my problem.

I'm trying to connect a client to the Photon self hosted server.
I use PhotonControl, I started "LoadBalancing / Start as Application". I haven't touched the configurations yet.

I need your help. In the console of Unity, i've the log "Try to connect to : 127.0.0.1:5055".
But no callbacks are called.

PS: The Connect function is called by another class.

THANK YOU in advance :smiley:

I'm developing a client on Unity (in C#), here is the code of my client:

class MyClient : IConnectionCallbacks
{
private LoadBalancingClient loadBalancingClient;

public MyClient()
{
this.loadBalancingClient = new LoadBalancingClient();
this.SubscribeToCallbacks();
}

~MyClient()
{
this.UnsubscribeFromCallbacks();
}

private void SubscribeToCallbacks()
{
this.loadBalancingClient.AddCallbackTarget(this);
}

private void UnsubscribeFromCallbacks()
{
this.loadBalancingClient.RemoveCallbackTarget(this);
}

public void Connect(string address, int port)
{
this.loadBalancingClient.MasterServerAddress = string.Format("{0}:{1}", address, port);
Debug.Log("Try to connect to : " + this.loadBalancingClient.MasterServerAddress);
this.loadBalancingClient.ConnectToMasterServer();
}

void IConnectionCallbacks.OnConnected()
{
Debug.Log("Connected");
// client is now connected to Photon Master Server and ready to create or join rooms
}

void IConnectionCallbacks.OnConnectedToMaster()
{
Debug.Log("Connected To Master");
// client is now connected to Photon Master Server and ready to create or join rooms
}

void IConnectionCallbacks.OnDisconnected(DisconnectCause cause)
{
Debug.Log("Disconnected: " + cause.ToString());
// client is now discconnected from Photon Master Server
}

void IConnectionCallbacks.OnRegionListReceived(RegionHandler handler)
{
Debug.Log("Region List : ");
// client is now discconnected from Photon Master Server
}

void IConnectionCallbacks.OnCustomAuthenticationResponse(Dictionary<string, object> response)
{
}

void IConnectionCallbacks.OnCustomAuthenticationFailed(string fail)
{
}
}

Comments

  • Hi, @Artoliz

    did you try test client that you can start from PhotonControl ?

    best,
    ilya
  • Hi @Artoliz,

    Thank you for choosing Photon!

    I think you missed calling LoadBalancingClient.Service periodically in a background thread.
    This is an important step to do.
    In the Unity SDK there is ConnectionHandler component which could help you with this.

    If you use Unity, why not simply use PUN 2? it's easier, simpler and has more learning resources. It's built on top of Photon Realtime so it has all its features and adds more.
  • Hi @JohnTube,

    Thank you for your reply.

    I installed the PUN2 package on Unity, and when I run 'Play' I have a 'PhotonMono' gameobject with a 'PhotonHandler' component derived from 'ConnectionHandler' which does the update alone.

    I use PUN2 on Unity (the asset store package). I want to use a self hosted server because I need to create server-side logic.

    I already have projects where the MasterClient (from photon) handles the game logic. But that doesn't suit me anymore.

    Best,
    Artoliz
  • I finally succeeded...

    I made some changes to the code:

    I connect using the 'PhotonNetwork.ConnectToMaster(address, port, appId)'
    My 'MyClient' class is now derived from 'MonoBehaviourPunCallbacks' and is attached to a gameobject from my scene.

    I can now connect to my local server. But... I don't see any logs on my self-hosted server telling me that my client is connected.
  • I'm having the same issue around the same location. I'm able to run Photon Control and successfully run and connect with the Test Client on my local machine.

    My app currently works with the Cloud Server, but when I try to connect to the local server, it seems to connect and authenticate but fails to create a room or to get any further.
  • hi!

    @Artoliz please use log4net.config to switch on DEBUG logging
    @floatingfactory please do same and send us logs

    best,
    ilya

  • @Artoliz Hi, @chvetsov mod @floatingfactory
    1) can you please tell me how you connect the game to your own dedicated server. We are looking for the same thing. can you please let us know the steps you followed. I'm also using photon pun2 free version but unable to connect to my own server.

    2) PhotonNetwork.ConnectToMaster(address, port, appId) - you written this statement in update function? can you please give us the script?

    3) class MyClient : IConnectionCallbacks
    {
    private LoadBalancingClient loadBalancingClient;

    public MyClient()
    {..
    .
    .
    .
    where you add this logic in you game?

    Thanks in advance.
  • hi, @Suraj

    you can ask this in PUN forum section. please do

    AFIK you just have to update settings in PUN and that is it

    best,
    ilya