public void Connect()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);

            var options = CreateOptions();            
            var uri = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                log.Info("EVENT_CONNECT");
                socket.Disconnect();
            });

            socket.On(Socket.EVENT_DISCONNECT,
                (data) =>
                {
                    log.Info("EVENT_DISCONNECT");
                    Message = (string) data;
                    ManualResetEvent.Set();
                });

            //socket.Open();
            ManualResetEvent.WaitOne();
            socket.Close();
            Assert.Equal("io client disconnect", this.Message);
        }
Example #2
0
        public async Task ShouldReconnectByDefault()
        {
            var log = LogManager.GetLogger(Global.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag             = false;

            var options = CreateOptions();
            var uri     = CreateUri();

            var manager = new Manager(new Uri(uri), options);

            socket = manager.Socket("/");

            manager.On(Socket.EVENT_RECONNECT, () =>
            {
                log.Info("EVENT_RECONNECT");
                Flag = true;
                socket.Disconnect();
                ManualResetEvent.Set();
            });

            await Task.Delay(500);

            log.Info("before EngineSocket close");
            manager.EngineSocket.Close();

            ManualResetEvent.WaitOne();
            Assert.True(Flag);
        }
Example #3
0
 void Disconnect()
 {
     if (socket != null)
     {
         socket.Disconnect();
         socket = null;
     }
 }
Example #4
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            loggingEvent.Fix = this.Fix;
            //ManualResetEvent ManualResetEvent = null;
            Quobject.SocketIoClientDotNet.Client.Socket socket = IO.Socket(m_serverUrl); //new Client(m_serverUrl);
            ManualResetEvent ManualResetEvent = new ManualResetEvent(false);

            string output = JsonConvert.SerializeObject(new
            {
                HostName        = Environment.MachineName,
                LoggrName       = loggingEvent.LoggerName,
                Level           = loggingEvent.Level.DisplayName,
                Message         = loggingEvent.RenderedMessage,
                ThreadName      = loggingEvent.ThreadName,
                TimeStamp       = loggingEvent.TimeStamp,
                ClassName       = loggingEvent.LocationInformation.ClassName,
                FileName        = loggingEvent.LocationInformation.FileName,
                LineNumber      = loggingEvent.LocationInformation.LineNumber,
                MethodName      = loggingEvent.LocationInformation.MethodName,
                StackFrames     = loggingEvent.LocationInformation.StackFrames,
                UserName        = loggingEvent.UserName,
                ExceptionString = loggingEvent.GetExceptionString(),
                Domain          = loggingEvent.Domain,
                Identity        = loggingEvent.Identity,
                Propeties       = loggingEvent.Properties
            }, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings
            {
                CheckAdditionalContent     = true,
                ConstructorHandling        = Newtonsoft.Json.ConstructorHandling.AllowNonPublicDefaultConstructor,
                MetadataPropertyHandling   = Newtonsoft.Json.MetadataPropertyHandling.ReadAhead,
                MissingMemberHandling      = Newtonsoft.Json.MissingMemberHandling.Ignore,
                NullValueHandling          = Newtonsoft.Json.NullValueHandling.Include,
                ObjectCreationHandling     = Newtonsoft.Json.ObjectCreationHandling.Reuse,
                PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All,
                ReferenceLoopHandling      = Newtonsoft.Json.ReferenceLoopHandling.Serialize
            });
            JObject jobj = JObject.Parse(output);

            try
            {
                socket.On(Socket.EVENT_CONNECT, () =>
                {
                    //socket.Emit("nickname", Environment.MachineName);
                    socket.Emit("sendMessage", jobj);
                    ManualResetEvent.Set();
                });
                ManualResetEvent.WaitOne(5000, true);
                socket.Disconnect();
                socket.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError("<<<< WebSocketAppender ERROR >>>> {0}", ex.ToString());
            }
        }
Example #5
0
        public void ShouldOpenANewNamespaceAfterConnectionGetsClosed()
        {
            var log = LogManager.GetLogger(Global.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag             = false;

            var options = CreateOptions();
            var uri     = CreateUri();

            var manager = new Manager(new Uri(uri), options);

            socket = manager.Socket("/");

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                socket.Disconnect();
            });

            socket.On(Socket.EVENT_DISCONNECT, () =>
            {
                var foo = manager.Socket("/foo");
                foo.On(Socket.EVENT_CONNECT, () =>
                {
                    Flag = true;
                    foo.Disconnect();
                    socket.Disconnect();
                    manager.Close();
                    ManualResetEvent.Set();
                });
                foo.Open();
            });
            ManualResetEvent.WaitOne();
            Assert.True(Flag);
        }
Example #6
0
        private void ConexaoSocket()
        {
            try
            {
                socket.Disconnect();
            }
            catch { }

            socket = IO.Socket(txtIP.Text);


            socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("entrar", "matheus");
            });

            string conteudo = "";

            socket.On("update", (data) =>
            {
                conteudo += data.ToString() + "\n";
                SetControlPropertyValue(rtbLog, "text", conteudo);
            });
        }
        public SocketService(string server, string userToken = "5601ab2d299cfb5a7698566158fcb2bc350701b9ac77b6f72e52c260fab0da57") : this(server)
        {
            UserToken        = userToken;
            EventsDictionary = new ConcurrentDictionary <string, object>();
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidateCert;
            var options = new IO.Options()
            {
                AutoConnect = true,
                //ExtraHeaders = new Dictionary<string, string>() { { authToken, UserToken } },
                Reconnection      = true,
                ReconnectionDelay = 10,
            };
            options.Transports = ImmutableList.Create <string>(Polling.NAME);

            socket = IO.Socket(server, options);
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                socket.Emit($"/v1/login/{UserToken}");
            });
            socket.On(Socket.EVENT_DISCONNECT, () =>
                      Debug.WriteLine("Disconnecting")
                      );
            socket.On(
                Socket.EVENT_ERROR, ErrorLog);
            socket.On("hi", (data) =>
            {
                Debug.WriteLine(data);
                socket.Disconnect();
            });

            socket.On(Socket.EVENT_MESSAGE, (data) =>
            {
                Debug.WriteLine("Message recieved");
            });
            socket.On(Socket.EVENT_CONNECT_ERROR, ErrorLog);
            socket.On(Socket.EVENT_RECONNECT_ATTEMPT, () => Debug.WriteLine("Attempting reconnect"));
            socket.On(Socket.EVENT_RECONNECT_ERROR, ErrorLog);
            socket.On(Socket.EVENT_RECONNECT_FAILED, () => Debug.WriteLine("Reconnect failed"));
        }
        public void ShouldNotTryToReconnectWithIncorrectPortWhenReconnectionDisabled()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag = false;


            var options = CreateOptions();
            options.Reconnection = false;
            var uri = "http://localhost:3940";

            var manager = new Manager(new Uri(uri), options);
            socket = manager.Socket("/invalid");

            manager.On(Manager.EVENT_RECONNECT_ATTEMPT, () =>
            {
                Flag = true;
            });

            manager.On(Manager.EVENT_CONNECT_ERROR, async () =>
            {
                // set a timeout to let reconnection possibly fire
                log.Info("EVENT_CONNECT_ERROR");
                await Task.Delay(1000);
                ManualResetEvent.Set();
            });

            ManualResetEvent.WaitOne();
            log.Info("after WaitOne");
            socket.Disconnect();
            manager.Close();
            Assert.False(Flag);     
        }
        public void ShouldTryToReconnectTwiceAndFailWhenRequestedTwoAttemptsWithIncorrectAddressAndReconnectEnabled()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag = false;
            var reconnects = 0;

            var options = CreateOptions();
            options.Reconnection = true;
            options.ReconnectionAttempts = 2;
            options.ReconnectionDelay = 10;
            var uri = "http://localhost:3940";


            var manager = new Manager(new Uri(uri), options);
            socket = manager.Socket("/asd");

            manager.On(Manager.EVENT_RECONNECT_ATTEMPT, () =>
            {
                log.Info("EVENT_RECONNECT_ATTEMPT");
                reconnects++;
            });

            manager.On(Manager.EVENT_RECONNECT_FAILED, () =>
            {
                log.Info("EVENT_RECONNECT_FAILED");
                Flag = true;
                socket.Disconnect();
                manager.Close();
                ManualResetEvent.Set();
            });

            ManualResetEvent.WaitOne();
            Assert.Equal(2, reconnects);
        }
        public async Task ShouldReconnectByDefault()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag = false;

            var options = CreateOptions();
            var uri = CreateUri();

            var manager = new Manager(new Uri(uri), options);
            socket = manager.Socket("/");

            manager.On(Socket.EVENT_RECONNECT, () =>
            {
                log.Info("EVENT_RECONNECT");
                Flag = true;
                socket.Disconnect();
                ManualResetEvent.Set();
            });

            await Task.Delay(500);
            log.Info("before EngineSocket close");
            manager.EngineSocket.Close();

            ManualResetEvent.WaitOne();
            Assert.True(Flag);
        }
        public void ShouldOpenANewNamespaceAfterConnectionGetsClosed()
        {
            var log = LogManager.GetLogger(Global.CallerName());
            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag = false;

            var options = CreateOptions();
            var uri = CreateUri();

            var manager = new Manager(new Uri(uri), options);
            socket = manager.Socket("/");

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                socket.Disconnect();
            });

            socket.On(Socket.EVENT_DISCONNECT, () =>
            {
                var foo = manager.Socket("/foo");
                foo.On(Socket.EVENT_CONNECT, () =>
                {
                    Flag = true;
                    foo.Disconnect();
                    socket.Disconnect();
                    manager.Close();
                    ManualResetEvent.Set();
                });
                foo.Open();
            });
            ManualResetEvent.WaitOne();
            Assert.True(Flag);
        }
Example #12
0
 public void disconnectSocketServer()
 {
     socketServer.Disconnect();
 }
Example #13
0
 public void Disconnect()
 {
     _sio.Disconnect();
 }
Example #14
0
 void OnDestroy()
 {
     socket.Disconnect();
 }