Exemple #1
0
 public SocketClient(SocketClientSettings theSocketClientSettings)
 {
     prefixHandler        = new PrefixHandler();
     messageHandler       = new MessageHandler();
     socketClientSettings = theSocketClientSettings;
     token = new DataHoldingUserToken(0, 0);
 }
Exemple #2
0
        public Coroutine StartAndWaitConnect(TimeSpan span)
        {
            var splittedAddress = ServerAddress.Trim().Split(':');
            var ip   = splittedAddress[0].Trim();
            var port = Convert.ToInt32(splittedAddress[1].Trim());

            try
            {
                SocketClientSettings settings = new SocketClientSettings(new IPEndPoint(Dns.GetHostAddresses(ip)[0], port));
                mClient = new SocketClient(settings);
            }
            catch (Exception exception)
            {
                Logger.Error(exception.ToString());
                return(null);
            }

            mClient.MessageReceived += MessageReceived;
            mClient.OnDisconnected  += OnDisconnected;
            mClient.OnException     += ex =>
            {
                Logger.Error(ex.ToString());
            };

            mConnectedNotified   = false;
            mClient.OnConnected += () =>
            {
                mConnectedNotified = true;
                Logger.Debug("Connected.....");
            };

            try
            {
                mConnectTimeout = DateTime.Now + span;
                mClient.StartConnect();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }

            var co = this.StartCoroutine(Wait());

            return(co);
        }