We are creating a chat application in android platform. For server side we are usingWebApi,WebSocket and Message Handling Server a for interaction in asp.net c# Language. Now we want to show the typing indicator when chat user is typing in that chat So how can we identify on server side.
We have one example for get all live connection we are use this app .It will help you that how we using this functionality.
- public void GetAllConnections(string connectinoId)
- {
- try
- {
- Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- DnsEndPoint Ep = new DnsEndPoint(SiCore.Model.Common.ServerHost, SiCore.Model.Common.ServerPort);
- sender.Connect(Ep);
- if (sender.Connected)
- {
- sender.Send(Encoding.UTF8.GetBytes("Task:AllConnections\n" + connectinoId+ "<EOF>"));
-
- }
-
-
- byte[] bytes = new byte[8192];
-
- string result = "";
- bool eof = false;
-
- do
- {
- int bytesRec = sender.Receive(bytes);
- result += System.Text.Encoding.UTF8.GetString(bytes, 0, bytesRec);
- eof = result.IndexOf("<EOF>") > -1;
- bytes = new byte[8192];
- } while (!eof && sender.Connected);
- sender.Close();
-
-
- List<Connection> conns = JsonConvert.DeserializeObject<List<Connection>>(result);
-
- Clients.Caller.allConnections(conns);
- }
- catch (Exception)
- {
-
- }
- }
and we getting the live connection like this:
- #region Task:AllConnections
- if (s.Contains("Task:AllConnections"))
- {
- state.userName = datacontent;
- logger.Info("\n\n**********" + "Total Connections " + currentConnections.Count + "**********\n\n");
-
- List<object> conns = liveConnStore.GetAllConnections(currentConnections);
-
- logger.Info("\n\n**********" + "Total Connections " + conns.Count + "**********\n\n");
-
- serverHub.SendAllConnections(conns, datacontent);
-
- Send(handler, JsonConvert.SerializeObject(conns) + "<EOF>");
- }
- #endregion