Ejemplo n.º 1
0
            void IListener.Call(params object[] args)
            {
                object err = args[0];
                SocketEngineException error;

                if (err is Exception)
                {
                    error = new SocketEngineException("probe error", (Exception)err);
                }
                else if (err is string)
                {
                    error = new SocketEngineException("probe error: " + (string)err);
                }
                else
                {
                    error = new SocketEngineException("probe error");
                }
                error.Transport = _transport[0].Name;

                _freezeTransport.Call();

                var log = LogManager.GetLogger(GlobalHelper.CallerName());

                log.Info(string.Format("probe transport \"{0}\" failed because of error: {1}", error.Transport, err));
                _socket.Emit(EVENT_UPGRADE_ERROR, error);
            }
Ejemplo n.º 2
0
        protected Transport OnError(string message, Exception exception)
        {
            Exception err = new SocketEngineException(message, exception);

            this.Emit(EVENT_ERROR, err);

            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Transport Error: " + exception.ToString());

            return(this);
        }
Ejemplo n.º 3
0
        public void OnPacket(EnginePacket packet)
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            if (ReadyState == ReadyStateEnum.OPENING || ReadyState == ReadyStateEnum.OPEN)
            {
                log.Info(string.Format("socket received: type '{0}', data '{1}'", packet.Type, packet.Data));

                Emit(EVENT_PACKET, packet);
                Emit(EVENT_HEARTBEAT);

                if (packet.Type == EnginePacket.OPEN)
                {
                    OnHandshake(new HandshakeData((string)packet.Data));
                }
                else if (packet.Type == EnginePacket.PONG)
                {
                    this.SetPing();
                }
                else if (packet.Type == EnginePacket.ERROR)
                {
                    var err = new SocketEngineException("server error");
                    err.code = packet.Data;
                    this.Emit(EVENT_ERROR, err);
                }
                else if (packet.Type == EnginePacket.MESSAGE)
                {
                    Emit(EVENT_DATA, packet.Data);
                    Emit(EVENT_MESSAGE, packet.Data);
                }
            }
            else
            {
                log.Info(string.Format("OnPacket packet received with socket readyState '{0}'", ReadyState));
            }
        }
Ejemplo n.º 4
0
                void IListener.Call(params object[] args)
                {
                    if (_onTransportOpenListener.Parameters.Failed[0])
                    {
                        return;
                    }
                    var log = LogManager.GetLogger(GlobalHelper.CallerName());

                    var msg = (EnginePacket)args[0];

                    if (EnginePacket.PONG == msg.Type && "probe" == (string)msg.Data)
                    {
                        log.Info(
                            string.Format("probe transport '{0}' pong",
                                          _onTransportOpenListener.Parameters.Transport[0].Name));

                        _onTransportOpenListener.Parameters.Socket.Upgrading = true;
                        _onTransportOpenListener.Parameters.Socket.Emit(EVENT_UPGRADING,
                                                                        _onTransportOpenListener.Parameters.Transport[0]);
                        PriorWebsocketSuccess = WebSocket.NAME ==
                                                _onTransportOpenListener.Parameters.Transport[0].Name;

                        log.Info(
                            string.Format("pausing current transport '{0}'",
                                          _onTransportOpenListener.Parameters.Socket.Transport.Name));
                        ((Polling)_onTransportOpenListener.Parameters.Socket.Transport).Pause(
                            () =>
                        {
                            if (_onTransportOpenListener.Parameters.Failed[0])
                            {
                                return;
                            }
                            if (ReadyStateEnum.CLOSED == _onTransportOpenListener.Parameters.Socket.ReadyState ||
                                ReadyStateEnum.CLOSING == _onTransportOpenListener.Parameters.Socket.ReadyState)
                            {
                                return;
                            }

                            log.Info("changing transport and sending upgrade packet");

                            _onTransportOpenListener.Parameters.Cleanup[0]();

                            _onTransportOpenListener.Parameters.Socket.SetTransport(
                                _onTransportOpenListener.Parameters.Transport[0]);
                            List <EnginePacket> packetList = new List <EnginePacket>()
                            {
                                new EnginePacket(EnginePacket.UPGRADE)
                            };
                            try
                            {
                                _onTransportOpenListener.Parameters.Transport[0].Send(packetList);

                                _onTransportOpenListener.Parameters.Socket.Flush();
                                _onTransportOpenListener.Parameters.Socket.Upgrading = false;

                                _onTransportOpenListener.Parameters.Socket.Emit(EVENT_UPGRADE,
                                                                                _onTransportOpenListener.Parameters.Transport[0]);
                                _onTransportOpenListener.Parameters.Transport.RemoveAt(0);
                            }
                            catch (Exception e)
                            {
                                log.Error("", e);
                            }
                        });
                    }
                    else
                    {
                        log.Info(string.Format("probe transport '{0}' failed",
                                               _onTransportOpenListener.Parameters.Transport[0].Name));

                        var err = new SocketEngineException("probe error");
                        _onTransportOpenListener.Parameters.Socket.Emit(EVENT_UPGRADE_ERROR, err);
                    }
                }