Cant Connect !!

Options
Ascendion
Ascendion
edited May 2011 in DotNet
I'm working in Unity3D on an MMO project and I'm having problems getting my unity app to connect to the server I have created.

The server is more or less a stub with a single operation "Login" that always returns success. I've got the server running and I can connect to TCP 5055 with a telnet client and I do get an error in the logs when I type anything.. so the server is there.

From the client, I'm directly using PhotonPeer, but when I attempt a connection, PhotonPeer enters the connecting state for an extended period of time (more than a minute) and then reports that the server forcibly refused the connection (something I would expect if there were a firewall blocking the connection, or there was no listener on the port). My firewall is completely disabled, and as I mentioned, the listener is there and will accept telnet connections.

As used, my code creates an instance of my network singleton, attaches to the events, then calls the StartConnection method and makes update calls ever 25 frames... that is it.

I've gone through the MMO client sample code and cant see where I'm doing anything significantly different as far as the raw connection is concerned, so any help to figure out how I goofed up would be greatly appreciated !!

Here is the singleton I use to handle network connections throughout the game life cycle:
using System;
using System.Collections.Generic;

using UnityEngine;
using ExitGames.Client.Photon;

public delegate void DebugEventHandler(string message);

public class NetworkPeer : IPhotonPeerListener
{
    private static NetworkPeer mNetwork;

    public static NetworkPeer Instance
    {
        get
        {
            if (mNetwork == null) mNetwork = new NetworkPeer();
            return mNetwork;
        }
    }

    public event DebugEventHandler DebugMessage;

    private PhotonPeer mPeer;

    private List<String> mServers;
    private int mServerNdx;

    private ResultRouter mRouter;

    public event EventHandler Connected;
    public event EventHandler Disconnected;

    private NetworkPeer()
    {
        // setup the list of servers we are going to try (for testing only -- live setup will have a fixed address)
        mServers = new List<string>();
        mServers.Add("localhost:5055");
        mServers.Add("ke5crp.homeip.net:5055");
        mServerNdx = 0;

        // create a new router to handle dispatching operation results and events
        mRouter = new ResultRouter();

    }

    public void StartConnection()
    {
        // and attempt to connect to the first server on the list 
        mPeer = new PhotonPeer(this, true);
        try
        {
            mPeer.Connect(mServers[mServerNdx], "Frontier");
        }
        catch (Exception ex)
        {
            DebugPrint("Immediate Exception = " + ex.Message);
        }
    }

    public ResultRouter Router
    {
        get { return mRouter; }
    }

    public PhotonPeer Peer
    {
        get { return mPeer; }
    }

    public PeerStateValue Status
    {
        get { return mPeer.PeerState; }
    }

    private int mUpdateCnt = 0;

    public void Update()
    {
        if (++mUpdateCnt < 25) return;
        mUpdateCnt = 0;
        DebugPrint("Peer State = " + mPeer.PeerState);
        mPeer.Service();
    }

    private void DebugPrint(string msg)
    {
        if (DebugMessage != null) DebugMessage(msg);
    }

    public void DebugReturn(DebugLevel level, string message)
    {
        DebugPrint(message);
    }

    public void EventAction(byte eventCode, System.Collections.Hashtable photonEvent)
    {        
        throw new NotImplementedException();
    }

    public void OperationResult(byte opCode, int returnCode, System.Collections.Hashtable returnValues, short invocID)
    {
        mRouter.DispatchOperation(opCode, returnCode, returnValues, invocID);
    }

    public void PeerStatusCallback(StatusCode statusCode)
    {
        DebugPrint("Peer Status = " + statusCode);
        switch (statusCode)
        {
            case StatusCode.Connect:
                if (Connected != null) Connected(null, null);
                break;
            case StatusCode.Disconnect:
                if (++mServerNdx == mServers.Count) mServerNdx = 0;
                try
                {
                    mPeer.Connect(mServers[mServerNdx], "Frontier");
                }
                catch (Exception ex)
                {
                    DebugPrint("Immediate Exception = " + ex.Message);
                }
                DebugPrint("Trying " + mServers[mServerNdx]);
                if (Disconnected != null) Disconnected(null, null);
                break;
            default
                break;
        }
    }
}

Comments

  • Ascendion
    Options
    After additional testing:

    I doesn't matter if I use localhost or the LAN IP, the connection fails

    UDP gets stuck InitializingApplication

    telnet from another computer can still connect to the tcp port and trips an error in the logs if I try to type anything after connecting, so it really is connecting.
  • Tobias
    Options
    By default, Photon listens on TCP port 4530, not 5055. I assume you changed this in the server setup, as your server logs out your input.
    In which logfile (name) does your typing end up?
    Could you zip and attach your log files please?
  • Boris
    Options
    I think you are missing case StatusCode.ExceptionOnConnect and you might also want to log/handle other satus codes.
    What's that with the mUpdateCnt? In the code it's always 0 so service() is never called?
  • Ascendion
    Options
    Yes I changed the config.. I didn't want to have to change the server list on the client to switch back and forth between TCP and UDP testing. Call me lazy :)

    The errors show up in the instance log -- something about bad protocol (which isn't surprising since I doubt the server expects a "Hello" as the 1st data received <lol>)

    mUpdateCnt handling:
    The code :
    if (++mUpdateCnt < 25) return;
    mUpdateCnt = 0;
    at the top of the update method limits the calling of the service method to once ever 25 frames... note the increment of mUpdateCnt before the comparison.

    I only handle the status codes that seemed relevant, but all of them are logged by the DebugPrint at the top of PeerStatusCallback. the code does actually cycle through the list of servers attempting to contact each one and failing, frequently with exception callbacks, but always at some point trippng a disconnect callback.

    Anyway -- progress report -- last night I brought up the demo server and proved it worked with the wingrid client, just to make sure there is nothing goofy about my install, and while I was writing this, I noticed the demo server was still running, so I reconfigured my client to connect to Lite, and it came right up.. so my problem is server side... I'm going to look into that and I'll get back to you on this thread if I hit another brick wall.
  • Ascendion
    Options
    For future reference, this behavior happens when there is an exception in the CreatePeer processing. The problem is resolved and the client and server are talking perfectly :)

    I've also got the client side result parsing and dispatchimg working.

    Thanks for the help !!!