当前位置: 首页>>代码示例>>C#>>正文


C# UserContext.Send方法代码示例

本文整理汇总了C#中UserContext.Send方法的典型用法代码示例。如果您正苦于以下问题:C# UserContext.Send方法的具体用法?C# UserContext.Send怎么用?C# UserContext.Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserContext的用法示例。


在下文中一共展示了UserContext.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnReceive

        public static void OnReceive(UserContext context)
        {
            string data = string.Empty;

            try
            {
                mCounter++;
                data = context.DataFrame.ToString();
                Console.WriteLine("Data Received From [" + context.ClientAddress.ToString() + "] - " + data + " (" + data.Length.ToString() + " - " + mCounter.ToString() + ")");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }

            //context.Send("Hello2");
            if (data == "PING")
            {
                context.Send("PONG!");
            }
            else if (data == "abc")
            {
                string sendData = new string('x', 32768);
                context.Send(sendData);
            }
            else
            {
                //context.Send("Echo back: " + data);
            }
        }
开发者ID:vbguyny,项目名称:Alchemy-Websockets,代码行数:30,代码来源:Program.cs

示例2: HandleClient

 static void HandleClient(UserContext context)
 {
     while (true)
     {
         lock (ActiveContexts)
         {
             if (!ActiveContexts.Contains(context))
                 break;
             Write("Sending timestamp", context);
             context.Send(GetTimestamp());
         }
         Thread.Sleep(1000);
     }
 }
开发者ID:epicvrvs,项目名称:Voiddekk,代码行数:14,代码来源:Program.cs

示例3: OnClientReceive

 private void OnClientReceive(UserContext context)
 {
     var data = context.DataFrame.ToString();
     if (data == "Test")
     {
         if (_forever && _clientDataPass)
         {
             context.Send(data);
         }
     }
     else
     {
         _clientDataPass = false;
     }
 }
开发者ID:ActivePHOENiX,项目名称:Alchemy-Websockets,代码行数:15,代码来源:ClientServer.cs

示例4: OnReceive

        ///<summary>
        /// Event fired when a data is received from the Alchemy Websockets server instance.
        /// Parses data as JSON and calls the appropriate message or sends an error message.
        /// </summary>
        /// <param name="context">The user's connection context</param>
        public static void OnReceive(UserContext context)
        {
            try
            {
                cont = context;
                var json = context.DataFrame.ToString();
                Console.WriteLine(json);
                dynamic obj = JsonConvert.DeserializeObject(json);
                Console.WriteLine(obj.TYPE);
                if ((obj.TYPE) == ("IDENTIFICATION"))
                {
                    string name = "EyeTrackerClient";
                    var r = new Response { TYPE = "IDENTIFICATION", DATA = name };
                    context.Send(JsonConvert.SerializeObject(r));
                }

                if ((obj.TYPE) == ("IDENTIFICATION_COMPLETE"))
                {
                    // devo recuperare ID salvato su file ini per esempio!
                    // se è vuoto restituisco stringa vuota
                    // se c'è invece restituisco stringa con id: TYPE: MACHINE_ID, DATA: valore

                    XmlReader reader = XmlReader.Create("Settings.xml");
                    string ID = "";
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "EyeTracker")
                        {
                            ID = reader.GetAttribute(0);
                        }
                    }
                    if (ID.Equals(""))
                    {
                        var r = new Response { TYPE = "MACHINE_ID", DATA = "" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                    else
                    {
                        var r = new Response { TYPE = "MACHINE_ID", DATA = ID };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                }

                if ((obj.TYPE) == ("OFFSET_CALCULATION"))
                {
                    if ((obj.TODO) == ("true"))
                    {
                        var r = new Response { TYPE = "START_OFFSET_CALCULATION", DATA = "" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                    else
                    {
                        var r = new Response { TYPE = "READY_TO_PLAY", DATA = "" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                }

                if ((obj.TYPE) == ("CALCULATING"))
                {
                    // spedisco pacchetto TYPE: CALCULATING, DATA: data corrente in mill dal 1970
                    DateTime baseDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    TimeSpan diff = DateTime.UtcNow - baseDate;
                    var r = new Response { TYPE = "CALCULATING", DATA = (long)(diff.TotalMilliseconds) };
                    context.Send(JsonConvert.SerializeObject(r));
                }

                if ((obj.TYPE) == ("OFFSET_CALCULATION_COMPLETE"))
                {
                    int id = obj.MACHINE_ID;
                    //devo salvare valore ID dell'EyeTracker dentro il file xml
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    XmlWriter writer = XmlWriter.Create("Settings.xml", settings);
                    writer.WriteStartDocument();
                    writer.WriteComment("This file is generated by the program.");
                    writer.WriteStartElement("EyeTracker");
                    writer.WriteAttributeString("ID", id.ToString());
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Flush();
                    writer.Close();
                    var r = new Response { TYPE = "READY_TO_PLAY", DATA = "" };
                    context.Send(JsonConvert.SerializeObject(r));
                }

                if ((obj.TYPE) == ("TRAINING_SESSION"))
                {
                    int pID = obj.PATIENT_ID;
                    if (IDSession == pID )
                    {
                        var r = new Response { TYPE = "TRAINING_SESSION", DATA = "false" };
                        context.Send(JsonConvert.SerializeObject(r));
                    }
                    else
                    {
//.........这里部分代码省略.........
开发者ID:vegazrelli,项目名称:GazeTracker2.0,代码行数:101,代码来源:WSClient.cs

示例5: Send

 /// <summary>
 /// Send the specified message to the target user. 
 /// This method will JSON stringify the message object.
 /// </summary>
 /// <param name="message">The message object.</param>
 /// <param name="ctx">The user context.</param>
 public static void Send(object message, UserContext ctx)
 {
     string msg = JsonConvert.SerializeObject(message);
     ctx.Send(msg);
 }
开发者ID:DisruptionTheory,项目名称:WebDE,代码行数:11,代码来源:Server.cs

示例6: OnReceive

        static void OnReceive(UserContext context)
        {
            Console.WriteLine("Websocket sending update");
            string[] stuff = new string[] { Song, Artist, Album, AlbumURL, Volume, Time, Percentage.ToString()};

            var json = JsonConvert.SerializeObject(stuff);
            context.Send(json);
        }
开发者ID:JamieH,项目名称:SpotifyDash,代码行数:8,代码来源:Program.cs

示例7: LogIn

        private static void LogIn(dynamic obj, UserContext context)
        {
            conexion.Open();
            string searchUser = "SELECT * FROM usuarios where username = '" + (string)obj.username + "'";
            SQLiteCommand cmd = new SQLiteCommand(searchUser, conexion);
            SQLiteDataReader data = cmd.ExecuteReader();
            string password = "";
            string avatar = "";
            while (data.Read())
            {
                password = Convert.ToString(data[1]);
                avatar = Convert.ToString(data[2]);

            }
            conexion.Close();

            if (password == "" || password != (string)obj.password)
            {
                context.Send(Errores.LogInError("Nombre de usuario o contraseña incorrecta."));
            }
            else
            {
                Usuario tmpUsuario = new Usuario { Context = context };
                tmpUsuario.username = (string)obj.username;

               // if (!usuarioAlreadyLogIn(tmpUsuario))
               // {
                OnlineUsers.TryAdd(tmpUsuario.username, tmpUsuario);
               // }
                context.Send(Errores.LogInSuccess("", (string)obj.username, (string)obj.password));
            }
        }
开发者ID:edugonch,项目名称:ProyectoMoviles,代码行数:32,代码来源:Program.cs

示例8: ReConnectUser

        private static void ReConnectUser(dynamic obj, UserContext context)
        {
            var me = new Usuario { Context = context };

            me.username = obj.username;

               OnlineUsers.TryAdd(me.username, me);

               context.Send(getUserList());

               TellAllIamHere(me);
        }
开发者ID:edugonch,项目名称:ProyectoMoviles,代码行数:12,代码来源:Program.cs

示例9: OnReceive

        /// <summary>
        /// Event fired when a data is received from the Alchemy Websockets server instance.
        /// Parses data as JSON and calls the appropriate message or sends an error message.
        /// </summary>
        /// <param name="context">The user's connection context</param>
        public static void OnReceive(UserContext context)
        {
            Console.WriteLine("Received Data From :" + context.ClientAddress);

            try
            {
                var json = context.DataFrame.ToString();

                // <3 dynamics
                dynamic obj = JsonConvert.DeserializeObject(json);

                switch ((int)obj.Type)
                {
                    case (int)CommandType.Register:
                        Register(obj.Name.Value, context);
                        break;
                    case (int)CommandType.Message:
                        ChatMessage(obj.Message.Value, context);
                        break;
                    case (int)CommandType.NameChange:
                        NameChange(obj.Name.Value, context);
                        break;
                }
            }
            catch (Exception e) // Bad JSON! For shame.
            {
                var r = new Response {Type = ResponseType.Error, Data = new {e.Message}};

                context.Send(JsonConvert.SerializeObject(r));
            }
        }
开发者ID:simboyz,项目名称:Alchemy-Websockets-Example,代码行数:36,代码来源:Program.cs

示例10: Register

        /// <summary>
        /// Register a user's context for the first time with a username, and add it to the list of online users
        /// </summary>
        /// <param name="name">The name to register the user under</param>
        /// <param name="context">The user's connection context</param>
        private void Register(string identify, UserContext context)
        {
            var json = context.DataFrame.ToString();
            RequestToTossServer obj = JsonConvert.DeserializeObject<RequestToTossServer>(json);

            var u = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();
            u.Identity = obj.userIdentity;
            //OnlineUsers[u] = obj.userIdentity;

            ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.RegisterRes };
            var sjson = JsonConvert.SerializeObject(r);
            context.Send(sjson);
        }
开发者ID:step4u,项目名称:CallService,代码行数:18,代码来源:TossServer.cs

示例11: SendState

 private void SendState(UserContext context)
 {
     // Re-send the state if connected
     var conn = this.FindConnection(context);
     if (conn != null && conn.IsRegistered)
     {
         var response = new SyncResponse(SyncResponse.ResponseTypes.UpdateState);
         response.Data = new { State = _state };
         context.Send(response.ToString());
     }
 }
开发者ID:jrc60752,项目名称:iRacingAdminSync,代码行数:11,代码来源:Server.cs

示例12: OnConnected

 public static void OnConnected(UserContext context)
 {
     Console.WriteLine("Client Connected From : " + context.ClientAddress.ToString());
     UserContexts.TryAdd(context.ClientAddress.ToString(), context);
     context.Send("Hello from server (" + DateTime.Now.ToString() + ")");
 }
开发者ID:vbguyny,项目名称:Alchemy-Websockets,代码行数:6,代码来源:Program.cs

示例13: OnServerReceive

 private static void OnServerReceive(UserContext context)
 {
     var data = context.DataFrame.ToString();
     context.Send(data);
 }
开发者ID:ActivePHOENiX,项目名称:Alchemy-Websockets,代码行数:5,代码来源:ClientServer.cs

示例14: IsPlaying

        internal bool IsPlaying(UserContext client)
        {
            if (client == null)
                return false;

            var playing = false;
            var stopLoop = 0;

            OnEventDelegate tempReceive = (ctx) => {
                playing = (ctx.DataFrame.ToString() == "PLAYING");
                stopLoop = 10000;
            };

            client.SetOnReceive(tempReceive);
            client.Send("shutupify:PLAYING?");

            while (stopLoop < 50) {
                stopLoop++;
                Thread.Sleep(10);
            }

            client.SetOnReceive(this.OnReceive);
            return playing;
        }
开发者ID:Krizzzn,项目名称:shutupify,代码行数:24,代码来源:WebSocket.cs

示例15: OnReceive

 private void OnReceive(UserContext context)
 {
     if (context.DataFrame.ToString() == "PING")
         context.Send("PONG");
 }
开发者ID:Krizzzn,项目名称:shutupify,代码行数:5,代码来源:WebSocket.cs


注:本文中的UserContext.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。