コード例 #1
0
ファイル: Session.cs プロジェクト: NoeCalmness/CoreFrame
    public void Connect(Action <Session> onConnect = null)
    {
        if (connecting)
        {
            m_onConnect += onConnect;
            return;
        }

        Disconnect();

        m_onConnect += onConnect;

        state = SessionState.CONNECTING;

        var callback  = m_onConnect;
        var validHost = host;
        var family    = AddressFamily.Unknown;
        var hostInfo  = Util.ParseString <string>(SDKManager.GetValidHost(host), false, ',');

        if (hostInfo.Length != 2 || hostInfo[0] != "0" && hostInfo[0] != "1")
        {
            family = AddressFamily.Unknown;
            Logger.LogException("<b><color=#FFFFFF>[{0}]</color></b> Could not resolve host [{1}:{2}]! Family:{3}", m_typeName, host, port, hostInfo.Length > 0 ? hostInfo[0] : "-1");
        }
        else
        {
            family    = hostInfo[0] == "0" ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6;
            validHost = hostInfo[1];

            Logger.LogInfo("<b><color=#FFFFFF>[{0}]</color></b> Current Address: <b><color=#FAA000>[{1} -- {2}]</color></b>", m_typeName, family, validHost);
        }

        OnValidateHost(validHost, family, callback);
    }