public PureEngineIoSocket Open() { string transportName; if (RememberUpgrade && PriorWebsocketSuccess && Transports.Contains(WebSocket.NAME)) { transportName = WebSocket.NAME; } else { transportName = Transports[0]; } ReadyState = ReadyStateEnum.OPENING; var transport = CreateTransport(transportName); SetTransport(transport); Task.Run(() => { Logger.Log("Task.Run Open start"); transport.Open(); Logger.Log("Task.Run Open finish"); }); return(this); }
public Manager(Uri uri, Options opts) { if (opts == null) { opts = new Options(); } if (opts.Path == null) { opts.Path = "/socket.io"; } this.Opts = opts; this.Nsps = ImmutableDictionary.Create <string, Socket>(); this.Subs = new ConcurrentQueue <On.IHandle>(); this.Reconnection(opts.Reconnection); this.ReconnectionAttempts(opts.ReconnectionAttempts != 0 ? opts.ReconnectionAttempts : int.MaxValue); this.ReconnectionDelay(opts.ReconnectionDelay != 0 ? opts.ReconnectionDelay : 1000); this.ReconnectionDelayMax(opts.ReconnectionDelayMax != 0 ? opts.ReconnectionDelayMax : 5000); this.Timeout(opts.Timeout < 0 ? 20000 : opts.Timeout); this.ReadyState = ReadyStateEnum.CLOSED; this.Uri = uri; this.Attempts = 0; this.Encoding = false; this.PacketBuffer = new List <Parser.Packet>(); this.OpeningSockets = new HashSet <Socket>(); this.Encoder = new Parser.Parser.Encoder(); this.Decoder = new Parser.Parser.Decoder(); this.AutoConnect = opts.AutoConnect; if (AutoConnect) { Open(); } }
public Socket Open() { string transportName; if (RememberUpgrade && PriorWebsocketSuccess && Transports.Contains(WebSocket.NAME)) { transportName = WebSocket.NAME; } else { transportName = Transports[0]; } ReadyState = ReadyStateEnum.OPENING; var transport = CreateTransport(transportName); SetTransport(transport); // EventTasks.Exec((n) => Task.Run(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("Task.Run Open start"); transport.Open(); log2.Info("Task.Run Open finish"); }); return(this); }
public override void OnAuthorityChanged(bool isMine, bool controllerChanged) { base.OnAuthorityChanged(isMine, controllerChanged); if (!controllerChanged) { return; } /// IReadyable objects start life Unready by default. Non IReadyable objects will never be Unready. var iReadyable = this as IReadyable; if (ReferenceEquals(iReadyable, null) || iReadyable.AlwaysReady || _readyState != ReadyStateEnum.Unready) { ReadyState = ReadyStateEnum.Ready; } else if (!isActiveAndEnabled) { ReadyState = ReadyStateEnum.Disabled; } else { ReadyState = ReadyStateEnum.Unready; } }
public Manager(Uri uri, ManagerOptions opts) { if (opts == null) { opts = new ManagerOptions(); } if (opts.Path == null) { opts.Path = "/socket.io"; } this.Options = opts; this.Nsps = new System.Collections.Concurrent.ConcurrentDictionary <string, Socket>(); this.Subs = new Queue <On.IHandle>(); this.TasksQueue = new Queue <TaskWorker>(); this.Reconnection(opts.Reconnection); this.ReconnectionAttempts(opts.ReconnectionAttempts != 0 ? opts.ReconnectionAttempts : int.MaxValue); this.ReconnectionDelay(opts.ReconnectionDelay != 0 ? opts.ReconnectionDelay : 1000); this.ReconnectionDelayMax(opts.ReconnectionDelayMax != 0 ? opts.ReconnectionDelayMax : 5000); this.Timeout(opts.Timeout < 0 ? 20000 : opts.Timeout); this.ReadyState = ReadyStateEnum.CLOSED; this.Uri = uri; this.Connected = 0; this.Attempts = 0; this.Encoding = false; this.PacketBuffer = new List <Packet>(); this.Encoder = new Parser.Encoder(); this.Decoder = new Parser.Decoder(); this.AutoConnect = opts.AutoConnect; if (AutoConnect) { Open(); } }
private void OnClose(string reason, Exception desc = null) { if (this.ReadyState == ReadyStateEnum.OPENING || this.ReadyState == ReadyStateEnum.OPEN) { var log = LogManager.GetLogger(GlobalHelper.CallerName()); log.Info(string.Format("OnClose socket close with reason: {0}", reason)); // clear timers if (this.PingIntervalTimer != null) { this.PingIntervalTimer.Stop(); } if (this.PingTimeoutTimer != null) { this.PingTimeoutTimer.Stop(); } //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; var temporaryTimer = EasyTimer.SetTimeout(() => { lock (WriteBuffer) { WriteBuffer.Clear(); } CallbackBuffer = new List <Action>(); PrevBufferLen = 0; }, 1); if (this.Transport != null) { // stop event from firing again for transport this.Transport.Off(EVENT_CLOSE); // ensure transport won't stay open this.Transport.Close(); // ignore further transport communication this.Transport.Off(); } // set ready state this.ReadyState = ReadyStateEnum.CLOSED; // clear session id this.Id = null; // emit close events this.Emit(EVENT_CLOSE, reason, desc); temporaryTimer.Stop(); } }
private void OnOpen() { var log = LogManager.GetLogger(Global.CallerName()); log.Info("open"); Cleanup(); ReadyState = ReadyStateEnum.OPEN; Emit(EVENT_OPEN); var socket = EngineSocket; var sub = Client.On.Create(socket, Engine.EVENT_DATA, new ListenerImpl((data) => { if (data is string) { OnData((string)data); } else if (data is byte[]) { Ondata((byte[])data); } })); lock (Subs) { Subs.Enqueue(sub); } sub = Client.On.Create(this.Decoder, Parser.Parser.Decoder.EVENT_DECODED, new ListenerImpl((data) => { OnDecoded((Parser.Packet)data); })); lock (Subs) { Subs.Enqueue(sub); } sub = Client.On.Create(socket, Engine.EVENT_ERROR, new ListenerImpl((data) => { OnError((Exception)data); })); lock (Subs) { Subs.Enqueue(sub); } sub = Client.On.Create(socket, Engine.EVENT_CLOSE, new ListenerImpl((data) => { OnClose((string)data); })); lock (Subs) { Subs.Enqueue(sub); } }
public Transport Open() { if (ReadyState == ReadyStateEnum.CLOSED) { ReadyState = ReadyStateEnum.OPENING; DoOpen(); } return(this); }
public void OnCloseForSocket(string reason) { var log = LogManager.GetLogger(Global.CallerName()); log.Info("start"); Cleanup(); ReadyState = ReadyStateEnum.CLOSED; if (_reconnection && !SkipReconnect) { Reconnect(); } }
private void OnClose(string reason, Exception desc = null) { if (_readyState == ReadyStateEnum.Opening || _readyState == ReadyStateEnum.Open) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("OnClose socket close with reason: {0}", reason)); // clear timers if (_pingIntervalTimer != null) { _pingIntervalTimer.Stop(); } if (_pingTimeoutTimer != null) { _pingTimeoutTimer.Stop(); } //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { _writeBuffer = ImmutableList <Packet> .Empty; _callbackBuffer = ImmutableList <Action> .Empty; _prevBufferLen = 0; }, 1); if (Transport != null) { // stop event from firing again for transport Transport.Off(EventClose); // ensure transport won't stay open Transport.Close(); // ignore further transport communication Transport.Off(); } // set ready state _readyState = ReadyStateEnum.Closed; // clear session id Id = null; // emit close events Emit(EventClose, reason, desc); } }
private void OnClose(string reason) { var log = LogManager.GetLogger(Global.CallerName()); log.Info("start"); Cleanup(); ReadyState = ReadyStateEnum.CLOSED; Emit(EVENT_CLOSE, reason); if (_reconnection && !SkipReconnect) { Reconnect(); } }
protected void OnClose() { ReadyState = ReadyStateEnum.CLOSED; if (this.Socket != null && this.Socket.TasksQueue != null) { var item = this.Socket.TasksQueue.FirstOrDefault(); if (item != null) { item.CancelAll(this.Socket.TasksQueue); } } Emit(EVENT_CLOSE); }
public void OnPackObjReadyChange(Component pobj, ReadyStateEnum readyState) { int packObjIndex = packObjIndexLookup[pobj]; if (readyState != ReadyStateEnum.Unready) { packObjReadyMask[packObjIndex] = true; } else { packObjReadyMask[packObjIndex] = false; } AllObjsAreReady = syncObjReadyMask.AllAreTrue && packObjReadyMask.AllAreTrue; }
public void OnSyncObjReadyChange(ISyncObject sobj, ReadyStateEnum readyState) { int syncObjIndex = sobj.SyncObjIndex; if (readyState != ReadyStateEnum.Unready) { syncObjReadyMask[syncObjIndex] = true; } else { syncObjReadyMask[syncObjIndex] = false; } AllObjsAreReady = syncObjReadyMask.AllAreTrue && packObjReadyMask.AllAreTrue; }
public SocketEngine Open() { string transportName; if (RememberUpgrade && PriorWebsocketSuccess && Transports.Contains(WebSocket.NAME)) { transportName = WebSocket.NAME; } else { transportName = Transports[0]; } transportName = WebSocket.NAME; ReadyState = ReadyStateEnum.OPENING; var transport = CreateTransport(transportName); SetTransport(transport); //EasyTimer.TaskRunNoWait(() => //{ // var log2 = LogManager.GetLogger(GlobalHelper.CallerName()); // log2.Info("Task.Run Open start"); // transport.Open(); // log2.Info("Task.Run Open finish"); //}); if (TasksQueue == null) { TasksQueue = new Queue <TaskWorker>(); } var task = new TaskWorker(null); task.QueueWorker( TasksQueue, null, (x, e) => { var log2 = LogManager.GetLogger(GlobalHelper.CallerName()); log2.Info("Task.Run Open start"); transport.Open(); log2.Info("Task.Run Open finish"); }, null, null, null ); return(this); }
public void Close() { this.SkipReconnect = true; this.Reconnecting = false; if (ReadyState != ReadyStateEnum.OPEN) { Cleanup(); } ReadyState = ReadyStateEnum.CLOSED; if (EngineSocket != null) { this.EngineSocket.Close(); } }
internal void OnClose(string reason, Exception desc = null) { if (ReadyState == ReadyStateEnum.OPENING || ReadyState == ReadyStateEnum.OPEN) { Logger.Log($"OnClose socket close with reason: {reason}"); // clear timers _pingIntervalTimer?.Stop(); _pingTimeoutTimer?.Stop(); //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { WriteBuffer = ImmutableList <Packet> .Empty; CallbackBuffer = ImmutableList <Action> .Empty; PrevBufferLen = 0; }, 1); if (Transport != null) { // stop event from firing again for transport Transport.Off(EVENT_CLOSE); // ensure transport won't stay open Transport.Close(); // ignore further transport communication Transport.Off(); } // set ready state ReadyState = ReadyStateEnum.CLOSED; // clear session id Id = null; // emit close events Emit(EVENT_CLOSE, reason, desc); } }
internal void OnOpen() { Logger.Log("socket open before call to flush()"); ReadyState = ReadyStateEnum.OPEN; PriorWebsocketSuccess = WebSocket.NAME == Transport.Name; Flush(); Emit(EVENT_OPEN); if (ReadyState == ReadyStateEnum.OPEN && Upgrade && Transport is Polling) //if (ReadyState == ReadyStateEnum.OPEN && Upgrade && this.Transport) { Logger.Log("OnOpen starting upgrade probes"); _errorCount = 0; foreach (var upgrade in Upgrades) { Probe(upgrade); } } }
private void OnOpen() { var log = LogManager.GetLogger(Global.CallerName()); ReadyState = ReadyStateEnum.OPEN; PriorWebsocketSuccess = WebSocket.NAME == Transport.Name; Flush(); Emit(EVENT_OPEN); if (ReadyState == ReadyStateEnum.OPEN && Upgrade && Transport is Polling) { log.Info("OnOpen starting upgrade probes"); _errorCount = 0; foreach (var upgrade in Upgrades) { Probe(upgrade); } } }
private void OnOpen() { var log = LogManager.GetLogger(Global.CallerName()); //log.Info("socket open before call to flush()"); _readyState = ReadyStateEnum.Open; PriorWebsocketSuccess = WebSocket.NAME == Transport.Name; Flush(); Emit(EventOpen); if (_readyState == ReadyStateEnum.Open && _upgrade && Transport is Polling) //if (ReadyState == ReadyStateEnum.OPEN && Upgrade && this.Transport) { log.Info("OnOpen starting upgrade probes"); _errorCount = 0; foreach (var upgrade in _upgrades) { Probe(upgrade); } } }
protected void OnOpen() { ReadyState = ReadyStateEnum.OPEN; Writable = true; Emit(EVENT_OPEN); }
public override void OnPostDisable() { base.OnPostDisable(); /// Disabled SyncObjs should be considered ready, so they don't hold up the visibility endlessly ReadyState = ReadyStateEnum.Disabled; }
public Socket Open() { string transportName; if (RememberUpgrade && PriorWebsocketSuccess && Transports.Contains(WebSocket.NAME)) { transportName = WebSocket.NAME; } else { transportName = Transports[0]; } ReadyState = ReadyStateEnum.OPENING; var transport = CreateTransport(transportName); SetTransport(transport); // EventTasks.Exec((n) => Task.Run(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("Task.Run Open start"); transport.Open(); log2.Info("Task.Run Open finish"); }); return this; }
private void OnClose(string reason, Exception desc = null) { if (this.ReadyState == ReadyStateEnum.OPENING || this.ReadyState == ReadyStateEnum.OPEN) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("OnClose socket close with reason: {0}", reason)); // clear timers if (this.PingIntervalTimer != null) { this.PingIntervalTimer.Stop(); } if (this.PingTimeoutTimer != null) { this.PingTimeoutTimer.Stop(); } //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { WriteBuffer = WriteBuffer.Clear(); CallbackBuffer = CallbackBuffer.Clear(); PrevBufferLen = 0; }, 1); // stop event from firing again for transport this.Transport.Off(EVENT_CLOSE); // ensure transport won't stay open this.Transport.Close(); // ignore further transport communication this.Transport.Off(); // set ready state this.ReadyState = ReadyStateEnum.CLOSED; // clear session id this.Id = null; // emit close events this.Emit(EVENT_CLOSE, reason, desc); } }
private Manager Open(IOpenCallback fn) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("readyState {0}", ReadyState)); if (ReadyState == ReadyStateEnum.OPEN) { return(this); } log.Info(string.Format("opening {0}", Uri)); EngineSocket = new Engine(Uri, Opts); Quobject.EngineIoClientDotNet.Client.Socket socket = EngineSocket; ReadyState = ReadyStateEnum.OPENING; OpeningSockets.Add(Socket(Uri.PathAndQuery)); SkipReconnect = false; var openSub = SocketIoClientDotNet.Client.On.Create(socket, Engine.EVENT_OPEN, new ListenerImpl(() => { OnOpen(); if (fn != null) { fn.Call(null); } })); var errorSub = Client.On.Create(socket, Engine.EVENT_ERROR, new ListenerImpl((data) => { log.Info("connect_error"); Cleanup(); ReadyState = ReadyStateEnum.CLOSED; EmitAll(EVENT_CONNECT_ERROR, data); if (fn != null) { var err = new SocketIOException("Connection error", data is Exception ? (Exception)data : null); fn.Call(err); } MaybeReconnectOnOpen(); })); if (_timeout >= 0) { var timeout = (int)_timeout; log.Info(string.Format("connection attempt will timeout after {0}", timeout)); var timer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("Manager Open start"); log2.Info(string.Format("connect attempt timed out after {0}", timeout)); openSub.Destroy(); socket.Close(); socket.Emit(Engine.EVENT_ERROR, new SocketIOException("timeout")); EmitAll(EVENT_CONNECT_TIMEOUT, timeout); log2.Info("Manager Open finish"); }, timeout); Subs.Enqueue(new On.ActionHandleImpl(timer.Stop)); ; } Subs.Enqueue(openSub); Subs.Enqueue(errorSub); EngineSocket.Open(); return(this); }
private void OnOpen() { var log = LogManager.GetLogger(Global.CallerName()); //log.Info("socket open before call to flush()"); ReadyState = ReadyStateEnum.OPEN; PriorWebsocketSuccess = WebSocket.NAME == Transport.Name; Flush(); Emit(EVENT_OPEN); if (ReadyState == ReadyStateEnum.OPEN && Upgrade && Transport is Polling) //if (ReadyState == ReadyStateEnum.OPEN && Upgrade && this.Transport) { log.Info("OnOpen starting upgrade probes"); _errorCount = 0; foreach (var upgrade in Upgrades) { Probe(upgrade); } } }
protected void OnClose() { ReadyState = ReadyStateEnum.CLOSED; Emit(EVENT_CLOSE); }
private Manager Open(IOpenCallback fn) { var log = LogManager.GetLogger(GlobalHelper.CallerName()); log.Info(string.Format("Manager readyState {0}", ReadyState)); if (ReadyState == ReadyStateEnum.OPEN) { return(this); // allready open } log.Info(string.Format("Manager opening {0}", Uri)); EngineSocket = new Engine(Uri, Options); SocketEngine socket = EngineSocket; ReadyState = ReadyStateEnum.OPENING; var openSub = SOCKETNET35.On.Create(socket, EVENT_OPEN, new ListenerImpl(() => { OnOpen(); if (fn != null) { fn.Call(null); } })); var errorSub = SOCKETNET35.On.Create(socket, EVENT_ERROR, new ListenerImpl((data) => { log.Info("connect_error"); Cleanup(); ReadyState = ReadyStateEnum.CLOSED; EmitAll(EVENT_CONNECT_ERROR, data); if (fn != null) { var err = new SocketException("Connection error", data is Exception ? (Exception)data : null); fn.Call(err); } MaybeReconnectOnOpen(); })); if (_timeout >= 0) { var timeout = (int)_timeout; log.Info(string.Format("connection attempt will timeout after {0}", timeout)); var timer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(GlobalHelper.CallerName()); log2.Info("Manager Open start"); log2.Info(string.Format("connect attempt timed out after {0}", timeout)); openSub.Destroy(); socket.Close(); socket.Emit(EVENT_ERROR, new SocketException("timeout")); EmitAll(EVENT_CONNECT_TIMEOUT, timeout); log2.Info("Manager Open finish"); }, timeout); //var taskWorker = new TaskWorker(this); //taskWorker.QueueWorkerWithDelay( // TasksQueue, // null, // (x, e) => // { // var log2 = LogManager.GetLogger(GlobalHelper.CallerName()); // log2.Info("Manager Open start"); // log2.Info(string.Format("connect attempt timed out after {0}", timeout)); // openSub.Destroy(); // socket.Close(); // socket.Emit(EVENT_ERROR, new SocketException("timeout")); // EmitAll(EVENT_CONNECT_TIMEOUT, timeout); // log2.Info("Manager Open finish"); // }, // (x, e) => // { // //action complete // }, // (e) => // { // //display error // }, // (x, e) => // { // // progress change // }, // timeout); lock (Subs) { Subs.Enqueue(new On.TimeoutActionHandle(timer.Stop)); //Subs.Enqueue(new On.ActionHandleImpl(taskWorker.Stop)); } } lock (Subs) { Subs.Enqueue(openSub); Subs.Enqueue(errorSub); } EngineSocket.Open(); return(this); }
public Manager(Uri uri, Options opts) { if (opts == null) { opts = new Options(); } if (opts.Path == null) { opts.Path = "/socket.io"; } this.Opts = opts; this.Nsps = ImmutableDictionary.Create<string, Socket>(); this.Subs = new Queue<On.IHandle>(); this.Reconnection(opts.Reconnection); this.ReconnectionAttempts(opts.ReconnectionAttempts != 0 ? opts.ReconnectionAttempts : int.MaxValue); this.ReconnectionDelay(opts.ReconnectionDelay != 0 ? opts.ReconnectionDelay : 1000); this.ReconnectionDelayMax(opts.ReconnectionDelayMax != 0 ? opts.ReconnectionDelayMax : 5000); this.Timeout(opts.Timeout < 0 ? 20000 : opts.Timeout); this.ReadyState = ReadyStateEnum.CLOSED; this.Uri = uri; this.Connected = 0; this.Attempts = 0; this.Encoding = false; this.PacketBuffer = new List<Parser.Packet>(); this.Encoder = new Parser.Parser.Encoder(); this.Decoder = new Parser.Parser.Decoder(); this.AutoConnect = opts.AutoConnect; if (AutoConnect) { Open(); } }
private void OnOpen() { var log = LogManager.GetLogger(Global.CallerName()); log.Info("open"); Cleanup(); ReadyState = ReadyStateEnum.OPEN; Emit(EVENT_OPEN); var socket = EngineSocket; var sub = Client.On.Create(socket, Engine.EVENT_DATA, new ListenerImpl((data) => { if (data is string) { OnData((string)data); } else if (data is byte[]) { Ondata((byte[])data); } })); Subs.Enqueue(sub); sub = Client.On.Create(this.Decoder, Parser.Parser.Decoder.EVENT_DECODED, new ListenerImpl((data) => { OnDecoded((Parser.Packet)data); })); Subs.Enqueue(sub); sub = Client.On.Create(socket, Engine.EVENT_ERROR, new ListenerImpl((data) => { OnError((Exception) data); })); Subs.Enqueue(sub); sub = Client.On.Create(socket, Engine.EVENT_CLOSE, new ListenerImpl((data) => { OnClose((string) data); })); Subs.Enqueue(sub); }
private Manager Open(IOpenCallback fn) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("readyState {0}", ReadyState)); if (ReadyState == ReadyStateEnum.OPEN) { return this; } log.Info(string.Format("opening {0}", Uri)); EngineSocket = new Engine(Uri, Opts); Quobject.EngineIoClientDotNet.Client.Socket socket = EngineSocket; ReadyState = ReadyStateEnum.OPENING; var openSub = SocketIoClientDotNet.Client.On.Create(socket, Engine.EVENT_OPEN, new ListenerImpl(() => { OnOpen(); if (fn != null) { fn.Call(null); } })); var errorSub = Client.On.Create(socket, Engine.EVENT_ERROR, new ListenerImpl((data) => { log.Info("connect_error"); Cleanup(); ReadyState = ReadyStateEnum.CLOSED; EmitAll(EVENT_CONNECT_ERROR, data); if (fn != null) { var err = new SocketIOException("Connection error", data is Exception ? (Exception) data : null); fn.Call(err); } MaybeReconnectOnOpen(); })); if (_timeout >= 0) { var timeout = (int) _timeout; log.Info(string.Format("connection attempt will timeout after {0}", timeout)); var timer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("Manager Open start"); log2.Info(string.Format("connect attempt timed out after {0}", timeout)); openSub.Destroy(); socket.Close(); socket.Emit(Engine.EVENT_ERROR, new SocketIOException("timeout")); EmitAll(EVENT_CONNECT_TIMEOUT, timeout); log2.Info("Manager Open finish"); }, timeout); Subs.Enqueue(new On.ActionHandleImpl(timer.Stop)); ; } Subs.Enqueue(openSub); Subs.Enqueue(errorSub); EngineSocket.Open(); return this; }
public Transport Open() { if (ReadyState == ReadyStateEnum.CLOSED) { ReadyState = ReadyStateEnum.OPENING; DoOpen(); } return this; }