コード例 #1
0
        private void init(NpCloudSocketType type, string url)
        {
            Regex regex;

            if (type != NpCloudSocketType.TCP)
            {
                if (type != NpCloudSocketType.Web)
                {
                    throw new NpCloudException(701, "Switchのcaseがdefaultだったよ = {0}");
                }
                regex = new Regex("ws://(?<host>.+):(?<port>[0-9]+)/\\?projectid=(?<projectId>.+)&me=(?<userId>.+)$");
            }
            else
            {
                regex = new Regex("tcp://(?<host>.+):(?<port>[0-9]+)/\\?projectid=(?<projectId>.+)&me=(?<userId>.+)$");
            }
            Match match = regex.Match(url);

            if (!match.Success)
            {
                throw new Exception("接続URLが不正です.");
            }
            this.HostName  = match.Groups["host"].Value;
            this.Port      = int.Parse(match.Groups["port"].Value);
            this.ProjectId = match.Groups["projectId"].Value;
            this.UserId    = uint.Parse(match.Groups["userId"].Value);
            IPHostEntry hostEntry = Dns.GetHostEntry(this.HostName);

            this.HostAddress = hostEntry.AddressList;
            if (this.HostAddress == null || this.HostAddress.Length == 0)
            {
                throw new Exception("IPアドレスが取得できません.");
            }
        }
コード例 #2
0
        private bool ConnectCore(NpCloudSocketType type, string url, Action connect)
        {
            bool result;

            try
            {
                this.mHandlerInstance.Active(true);
                this.mErrorCode = 0;
                this.mErrorMsg  = string.Empty;
                this.mCloudType = NpCloud.Type.None;
                NpCloudSocketSystem.CreateInstance(url, type, this.mHashKey);
                connect();
                if (this.mCloudType == NpCloud.Type.Error)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            catch (NpCloudException errorData)
            {
                this.SetErrorData(errorData);
                this.Exit(this.mErrorCode, this.mErrorMsg);
                result = false;
            }
            catch (Exception errorData2)
            {
                this.SetErrorData(errorData2);
                this.Exit(this.mErrorCode, this.mErrorMsg);
                result = false;
            }
            return(result);
        }
コード例 #3
0
        public void ConnectAsync(NpCloudSocketType type, string url, int timeOut, Action <bool> result, object option = null)
        {
            if (this.mCloudType != NpCloud.Type.None)
            {
                result(true);
                return;
            }
            this.mIsConnectAsync     = false;
            this.mConnectAsyncAction = result;
            Action connect = delegate()
            {
                Action <bool, Exception> result2 = delegate(bool flg, Exception e)
                {
                    this.ConnectResultAction(flg, e, result);
                };
                NpCloudSocketSystem.GetInstance().ConnectAsync(timeOut, result2, option);
                this.mCloudType = NpCloud.Type.Connecting;
            };

            if (!this.ConnectCore(type, url, connect))
            {
                this.mIsConnectAsync       = true;
                this.mIsConnectAsyncResult = false;
            }
        }
コード例 #4
0
        public bool Connect(NpCloudSocketType type, string url, int timeOut, object option = null)
        {
            if (this.mCloudType != NpCloud.Type.None)
            {
                return(true);
            }
            Action connect = delegate()
            {
                NpCloudSocketSystem instance = NpCloudSocketSystem.GetInstance();
                bool flag = false;
                global::Debug.Log("npCloudSocketSystem " + instance);
                if (instance != null)
                {
                    flag = instance.Connect(timeOut, option);
                }
                if (flag)
                {
                    this.mCloudType = NpCloud.Type.Idle;
                }
                else
                {
                    this.mCloudType = NpCloud.Type.Error;
                }
            };

            return(this.ConnectCore(type, url, connect));
        }
コード例 #5
0
 public static void CreateInstance(string url, NpCloudSocketType type, string hashKey)
 {
     if (NpCloudSocketSystem.instance != null)
     {
         return;
     }
     NpCloudSocketSystem.instance = new NpCloudSocketSystem(url, type, hashKey);
 }
コード例 #6
0
 private NpCloudSocketSystem(string url, NpCloudSocketType type, string hashKey)
 {
     this.mSetting = new NpCloudSetting(type, url);
     if (type != NpCloudSocketType.TCP)
     {
         if (type == NpCloudSocketType.Web)
         {
             this.mSocketSystem = new NpCloudWebSocketSystem(this.mSetting, hashKey);
         }
     }
     else
     {
         this.mSocketSystem = new NpCloudTCPSocketSystem(this.mSetting, hashKey);
     }
 }
コード例 #7
0
 public NpCloudSetting(NpCloudSocketType type, string url)
 {
     this.Url = url;
     this.init(type, url);
 }