private void OnOpen() { LogManager.GetLogger(Global.CallerName("", 0, "")).Info("open"); this.Cleanup(); this.ReadyState = Manager.ReadyStateEnum.OPEN; this.Emit(Manager.EVENT_OPEN); Quobject.EngineIoClientDotNet.Client.Socket engineSocket = this.EngineSocket; this.Subs.Enqueue(ClientOn.Create((Emitter)engineSocket, Quobject.EngineIoClientDotNet.Client.Socket.EVENT_DATA, (IListener) new ListenerImpl((Action <object>)(data => { if (data is string) { this.OnData((string)data); } else { if (!(data is byte[])) { return; } this.Ondata((byte[])data); } })))); this.Subs.Enqueue(ClientOn.Create((Emitter)this.Decoder, "decoded", (IListener) new ListenerImpl((Action <object>)(data => this.OnDecoded((Packet)data))))); this.Subs.Enqueue(ClientOn.Create((Emitter)engineSocket, Quobject.EngineIoClientDotNet.Client.Socket.EVENT_ERROR, (IListener) new ListenerImpl((Action <object>)(data => this.OnError((Exception)data))))); this.Subs.Enqueue(ClientOn.Create((Emitter)engineSocket, Quobject.EngineIoClientDotNet.Client.Socket.EVENT_CLOSE, (IListener) new ListenerImpl((Action <object>)(data => this.OnClose((string)data))))); }
private void SubEvents() { Manager io = this._io; this.Subs = ImmutableQueue.Create <ClientOn.IHandle>(); this.Subs = this.Subs.Enqueue(ClientOn.Create((Emitter)io, Manager.EVENT_OPEN, (IListener) new ListenerImpl(new ActionTrigger(this.OnOpen)))); this.Subs = this.Subs.Enqueue(ClientOn.Create((Emitter)io, Manager.EVENT_PACKET, (IListener) new ListenerImpl((Action <object>)(data => this.OnPacket((Packet)data))))); this.Subs = this.Subs.Enqueue(ClientOn.Create((Emitter)io, Manager.EVENT_CLOSE, (IListener) new ListenerImpl((Action <object>)(data => this.OnClose((string)data))))); }
private Manager Open(Manager.IOpenCallback fn) { LogManager log = LogManager.GetLogger(Global.CallerName("", 0, "")); log.Info(string.Format("readyState {0}", (object)this.ReadyState)); if (this.ReadyState == Manager.ReadyStateEnum.OPEN) { return(this); } log.Info(string.Format("opening {0}", (object)this.Uri)); this.EngineSocket = (Quobject.EngineIoClientDotNet.Client.Socket) new Engine(this.Uri, this.Opts); Quobject.EngineIoClientDotNet.Client.Socket socket = this.EngineSocket; this.ReadyState = Manager.ReadyStateEnum.OPENING; this.OpeningSockets.Add(this.Socket(this.Uri.PathAndQuery)); this.SkipReconnect = false; ClientOn.IHandle openSub = ClientOn.Create((Emitter)socket, EngineIoClientDotNet.Client.Socket.EVENT_OPEN, (IListener) new ListenerImpl((ActionTrigger)(() => { this.OnOpen(); if (fn == null) { return; } fn.Call((Exception)null); }))); ClientOn.IHandle handle = ClientOn.Create((Emitter)socket, EngineIoClientDotNet.Client.Socket.EVENT_ERROR, (IListener) new ListenerImpl((Action <object>)(data => { log.Info("connect_error"); this.Cleanup(); this.ReadyState = Manager.ReadyStateEnum.CLOSED; this.EmitAll(Manager.EVENT_CONNECT_ERROR, data); if (fn != null) { fn.Call((Exception) new SocketIOException("Connection error", data is Exception ? (Exception)data : (Exception)null)); } else { this.MaybeReconnectOnOpen(); } }))); if (this._timeout >= 0L && this.ReadyState == Manager.ReadyStateEnum.CLOSED) { int timeout = (int)this._timeout; log.Info(string.Format("connection attempt will timeout after {0}", (object)timeout)); this.Subs.Enqueue((ClientOn.IHandle) new ClientOn.ActionHandleImpl(new ActionTrigger(EasyTimer .SetTimeout((ActionTrigger)(() => { LogManager logger = LogManager.GetLogger(Global.CallerName("", 0, "")); logger.Info("Manager Open start"); logger.Info(string.Format("connect attempt timed out after {0}", (object)timeout)); openSub.Destroy(); socket.Close(); socket.Emit(Quobject.EngineIoClientDotNet.Client.Socket.EVENT_ERROR, (object)new SocketIOException("timeout")); this.EmitAll(Manager.EVENT_CONNECT_TIMEOUT, (object)timeout); logger.Info("Manager Open finish"); }), timeout).Stop))); } this.Subs.Enqueue(openSub); this.Subs.Enqueue(handle); this.EngineSocket.Open(); return(this); }