Connecting to local Server

Options
Cryr
edited March 2012 in Photon Server
Hi,

im new to Photon and Server Programming at all and encountered my first problem when trying to connect to my server (v.3.0.9) running on the same computer.
What i did so far:
Setting my own server Application and loading it on Instance1:
Server:
namespace MyMmoServer
{
    public class MyMmoServerApplication : ApplicationBase
    {

        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            return new MyMmoServerPeer(initRequest.Protocol, initRequest.PhotonPeer);
        }

        protected override void Setup()
        {

        }

        protected override void TearDown()
        {

        }
    }
}
Peer:
namespace MyMmoServer
{
    class MyMmoServerPeer : Peer, IOperationHandler
    {
        public MyMmoServerPeer(IRpcProtocol iRpcProtocol, PhotonHostRuntimeInterfaces.IPhotonPeer iPhotonPeer)
            : base(iRpcProtocol, iPhotonPeer)
        {
            this.SetCurrentOperationHandler(this);
        }

        public void OnDisconnect(PeerBase peer)
        {
            this.SetCurrentOperationHandler(null);
            this.Disconnect();
        }

        public void OnDisconnectByOtherPeer(PeerBase peer)
        {
            peer.RequestFiber.Enqueue(() => peer.RequestFiber.Enqueue(peer.Disconnect));
        }

        public OperationResponse OnOperationRequest(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            return new OperationResponse(operationRequest.OperationCode, new Dictionary<byte, object> {
                                                                { 100, "We get signal." } 
                                                            });
        }
    }
}

Instance1 is loading and running successfull this Code.

After this i started a fresh Unity3D Project and trying to Connect to my running Server.
Code:
public class Game : MonoBehaviour,  IPhotonPeerListener
{

    PhotonPeer peer;
    public string status = "unknown";
    public int SendIntervalMs = 200;
    private int NextSendTickCount = Environment.TickCount;

    public void Start()
    {
        Application.runInBackground = true;
        this.peer = new PhotonPeer(this, ConnectionProtocol.Udp);
    }

    private void Connect()
    {
        this.NextSendTickCount = Environment.TickCount + this.SendIntervalMs;
        try
        {
            this.peer.Connect("localhost:5055", "MyMmoServer");
            UnityEngine.Debug.LogWarning("Used Protocoll: " + peer.UsedProtocol.ToString());
        }
        catch (Exception e)
        {
            UnityEngine.Debug.LogWarning("Connect Exception:" + e.ToString());
        }
    }

    public void Update()
    {
        if ((peer.PeerState == PeerStateValue.Connected) && (Environment.TickCount > this.NextSendTickCount))
        {
            this.peer.Service();
            this.NextSendTickCount = Environment.TickCount + this.SendIntervalMs;
        }
        UnityEngine.Debug.LogWarning("Update PeerState: " + this.peer.PeerState.ToString());
    }

    public void OnGUI()
    {
        if (GUI.Button(new Rect(100, 60, 100, 30), "Connect"))
        {
            this.Connect();
        }
        if(GUI.Button(new Rect( 210, 60, 100, 30), "Disconnect"))
        {
            this.Disconnect();
        }
        GUI.Label(new Rect(100, 100, 300, 300), status);
    }


    public void OnStatusChanged(StatusCode statusCode)
    {
        ###snip###
    }

    public void Disconnect()
    {
        this.peer.Disconnect();
    }
}
According to different Tutorials and Sample Projects this should work and successful connect.
But my Debugging reveals, that my peer.PeerStatus is "Connecting" and never reach "Connected".
And if i try to peer.Service() anyways, my Server crashes.

Any hint pointing out the problem would be very useful.

Thanks in advance!

Edit: Testclient is running successful

Comments

  • Tobias
    Options
    The client side wont connect, if you don't include the Service call into your gameloop. It's not done by thread but instead fully in your control when and how much you send and dispatch (anything that arrived already).

    Instead of starting from scratch, you could use the client demo and modify it to connect to your new app (name). See what happens. You find out if it's a client or server issue.

    In your config, did you add "MyMmoServer" as (name of) one of your apps?
  • Cryr
    Options
    Hmmm. And there is the problem, when i try to call Service, my Server crashes. I did try the MMO Demo today and to my surprise, there was the same problem.
    The actual log Message when the server crashes is:
    CENetThreadPool::Process - Exception - CBuffer::Release() - m_ref is already 0
    
    and after a couple more Service calls a Runtime error occurs:
    R6025 - pure virtual function call
    

    The fact that the MmoDemo raises the same errors as my Code should point to a problem with my System or Photon!?

    Yes i did add MyMmoServer to my apps. The Server is running until my Service calls :(
  • Tobias
    Options
    I'm not sure where these errors come from but I checked our latest version and it works as expected.
    Maybe we fixed some issues which still affect your older version.

    Please update to ExitGames-Photon-Server-SDK_v3-0-19-2868-RC8.zip. Make sure to base all your changes in the included server code and the client that's in the SDK. The Unity "Grid Demo" is a quick way to verify it runs but it requires you to build the included solution.
  • Dears

    I have the same issue with peer.Service(), it also crash in the demo !!!


    NullReferenceException: Object reference not set to an instance of an object
    ExitGames.Client.Photon.EnetPeer.DeserializeMessageAndCallback (System.Byte[] inBuff)
    ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
    ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
    ExitGames.Client.Photon.PhotonPeer.Service ()
    Game.Service () (at Assets/Photon/Game.cs:349)
    Game.Update () (at Assets/Photon/Game.cs:68)
    usePhoton.Update () (at Assets/Photon/usePhoton.cs:123)

    can you please help me in this , i am using photon 3

    Thanks,
    Abed
  • Tobias
    Options
    abodehq: The issue you describe is client-side, not server-side. Please create a new topic for this and let us know which SDK versions you are using (client and server).
    Otherwise it's just impossible to help.

    Best: Update to the latest SDKs right away and re-try before starting a new thread.
    Thanks.