Exemple #1
0
        static void Login()
        {
            byte[]   data, msg;
            LoginReq loginReq = new LoginReq {
                Token = "eyJhbGciOiJIUzI1NiIsImtpZCI6ImtpZC1oZWFkZXIiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE1MzQ4NDMxNTIsInVpZCI6OTg2MzY0MzMxMjk0NzIxfQ.gvXdwFBIZEcbhYq37u4TUmzvJYF7LnLW0v3lteSEjAM"
            };

            using (MemoryStream stream = new MemoryStream()) {
                loginReq.WriteTo(stream);
                msg = stream.ToArray();
            }
            data = Utility.CombineCodeAndData(10101, msg);
            connection.Write(data);
        }
Exemple #2
0
        static async Task Run()
        {
            var connection = new WebSocketsConnection();
            await connection.Connect();

            var readerTask = connection.ReadDataForever();

            byte[]   data, message;
            LoginReq loginReq = new LoginReq {
                Token = "eyJhbGciOiJIUzI1NiIsImtpZCI6ImtpZC1oZWFkZXIiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE1MzQ0MDk2MjMsInVpZCI6OTg2MzY0MzMxMjk0NzIxfQ.I9hZKcVzG9QLujrFoOjkCaWGwLrVZqI5f_rM-TC-QcE"
            };

            using (MemoryStream stream = new MemoryStream()) {
                loginReq.WriteTo(stream);
                message = stream.ToArray();
            }


            Console.WriteLine("edwin #26 {0}", BytesToString(CombineCodeAndData(10101, message)));

            await connection.WriteData(CombineCodeAndData(10101, message));



            Thread.Sleep(5000);


            HeartBeatReq heartBeatReq = new HeartBeatReq {
            };

            using (MemoryStream stream = new MemoryStream()) {
                heartBeatReq.WriteTo(stream);
                data = stream.ToArray();
            }


            while (true)
            {
                Thread.Sleep(5000);
                await connection.WriteData(data);
            }
        }