2
Reply

Show typing indicator in android chat app using web-socket

Naveen Soni

Naveen Soni

Oct 22 2016 1:33 AM
636

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.
 
 
  1. public void GetAllConnections(string connectinoId)  
  2.         {  
  3.             try  
  4.             {  
  5.                 Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  
  6.                 DnsEndPoint Ep = new DnsEndPoint(SiCore.Model.Common.ServerHost, SiCore.Model.Common.ServerPort);  
  7.                 sender.Connect(Ep);                                 
  8.                 if (sender.Connected)  
  9.                 {  
  10.                     sender.Send(Encoding.UTF8.GetBytes("Task:AllConnections\n" + connectinoId+ "<EOF>"));  
  11.   
  12.                 }  
  13.   
  14.   
  15.                 byte[] bytes = new byte[8192];  
  16.   
  17.                 string result = "";  
  18.                 bool eof = false;  
  19.   
  20.                 do  
  21.                 {  
  22.                     int bytesRec = sender.Receive(bytes);  
  23.                     result += System.Text.Encoding.UTF8.GetString(bytes, 0, bytesRec);  
  24.                     eof = result.IndexOf("<EOF>") > -1;  
  25.                     bytes = new byte[8192];  
  26.                 } while (!eof && sender.Connected);  
  27.                 sender.Close();  
  28.   
  29.   
  30.                 List<Connection> conns = JsonConvert.DeserializeObject<List<Connection>>(result);  
  31.   
  32.                 Clients.Caller.allConnections(conns);  
  33.             }  
  34.             catch (Exception)  
  35.             {  
  36.                 //throw;  
  37.             }  
  38.         }  

and we getting the live connection like this:
  1. #region Task:AllConnections  
  2.                             if (s.Contains("Task:AllConnections"))  
  3.                             {  
  4.                                 state.userName = datacontent;  
  5.                                 logger.Info("\n\n**********" + "Total Connections " + currentConnections.Count + "**********\n\n");  
  6.   
  7.                                 List<object> conns = liveConnStore.GetAllConnections(currentConnections);  
  8.   
  9.                                 logger.Info("\n\n**********" + "Total Connections " + conns.Count + "**********\n\n");  
  10.   
  11.                                 serverHub.SendAllConnections(conns, datacontent);  
  12.   
  13.                                 Send(handler, JsonConvert.SerializeObject(conns) + "<EOF>");  
  14.                             }  
  15.                             #endregion  



Answers (2)