static void OnConnectionLost(MyEvent arg) { UnityClientEvent evt = arg as UnityClientEvent; Console.WriteLine("OnConnectionLost =>> success:" + evt.Success + ",parame :" + evt.Parame); client.Logger.Info("OnConnectionLost =>> success:" + evt.Success + ",parame :" + evt.Parame); }
static void OnHandSnake(MyEvent arg) { UnityClientEvent evt = arg as UnityClientEvent; HandSnakeResp resp = evt.GetParame <HandSnakeResp>(); client.Logger.Info("OnHandSnake =>> success:" + evt.Success + ",parame :" + resp); }
static void OnChannelDataError(MyEvent arg) { UnityClientEvent evt = arg as UnityClientEvent; HandSnakeResp resp = evt.GetParame <HandSnakeResp>(); Console.WriteLine("OnHandSnake:" + resp.GetType().FullName); }
static void OnConnectResum(MyEvent arg) { UnityClientEvent evt = arg as UnityClientEvent; HandSnakeResp resp = evt.GetParame <HandSnakeResp>(); Console.WriteLine("OnConnectResum:" + resp.GetType().FullName); }
public override void AddEventListener(string evtType, EventListenerDelegate <MyEvent> listener) { if (listener == null) { throw new ArgumentNullException("listen == null"); } if (!ClientEvent.ContainEventName(evtType) && !UnityClientEvent.ContainEventName(evtType) && !LoggerEvent.ContainEventName(evtType)) { Delegate[] delegateArray = listener.GetInvocationList(); object[] attributes = delegateArray[0].Method.GetCustomAttributes(typeof(NetCallBackParame), false); if (attributes == null || attributes.Length == 0) { throw new ArgumentNullException("Failed to add event listener,cause : Cloud not found the delegate method [NetCallBackeParame] attribute!"); } NetCallBackParame netCallBack = (NetCallBackParame)attributes[0]; Type type = netCallBack.ParameType; if (!typeof(ResponseArg).IsAssignableFrom(type)) { throw new ArgumentNullException("Failed to add event listener,cause : the delegate method attribute parame not extend ResponseArg"); } ResponseMappingInfo.Instance.AddResponeMapping(Int32.Parse(evtType), type); } base.AddEventListener(evtType, listener); }
private void HandlHandSnake(MyEvent evt) { UnityClientEvent ucEvt = evt as UnityClientEvent; if (evt.Success) { HandSnakeResp resp = evt.GetParame <HandSnakeResp>(); this.sessionToken = resp.ReconnectToken; if (this.debug) { string[] messages = new string[] { string.Format("Handshake response: sessionToken => {0}, heartbeatTime => {1}", this.sessionToken, resp.HeartbeatTime) }; this.log.Debug(messages); } if (this.client.IsReconnecting) { this.client.IsReconnecting = false; this.Dispatch(new UnityClientEvent(UnityClientEvent.CONNECTION_RESUME)); } else { this.isConnecting = false; this.Dispatch(new UnityClientEvent(UnityClientEvent.CONNECTION)); } } else { UnityClientEvent cEvt = new UnityClientEvent(UnityClientEvent.CONNECTION); cEvt.Success = false; cEvt.ErrorDes = "Failed to HandSnake"; this.Dispatch(cEvt); } }
static void OnConnect(MyEvent arg) { UnityClientEvent evt = arg as UnityClientEvent; client.Logger.Info("OnConnect =>> success:" + evt.Success + ",parame :" + evt.Parame); Thread thread = new Thread(sendLoginReq); thread.Start(); }
private void HandleConnectionProblem(MyEvent evt) { GeneralEventArgs event2 = evt as GeneralEventArgs; UnityClientEvent ucevt = new UnityClientEvent(UnityClientEvent.CONNECTION); ucevt.Success = false; ucevt.ErrorDes = event2.ErrorDes; ucevt.Parame = event2.Parame; this.Dispatch(ucevt); this.isConnecting = false; this.client.Destroy(); }
public void Connect(string host, int port, string password) { if (this.IsConnected) { string[] messages = new string[] { "Already connected" }; this.log.Warn(messages); } else if (this.isConnecting) { string[] textArray2 = new string[] { "A connection attempt is already in progress" }; this.log.Warn(textArray2); } else { if ((host == null) || (host.Length == 0)) { throw new ArgumentException("Invalid connection host/address"); } if ((port < 0) || (port > 0xffff)) { throw new ArgumentException("Invalid connection port"); } try { IPAddress.Parse(host); } catch (FormatException) { try { host = Dns.GetHostEntry(host).AddressList[0].ToString(); } catch (Exception exception) { string str = "Failed to lookup hostname " + host + ". Connection failed. Reason " + exception.Message; string[] textArray3 = new string[] { str }; this.log.Error(textArray3); UnityClientEvent evt = new UnityClientEvent(UnityClientEvent.CONNECTION); evt.Success = false; evt.ErrorDes = str; this.Dispatch(evt); return; } } this.lastConnectHost = host; this.isConnecting = true; this.client.Connect(host, port); } }