internal static bool SendMessage(ClientCall remoteCall, bool throwException = true) { if (remoteCall == null) throw new ArgumentNullException("remoteCall"); //check if the id exists if (!clientStreams.ContainsKey(remoteCall.ClientId)) { if (throwException) throw new Exception("ClientId does not exist"); else return false; } //get the stream var st = clientStreams[remoteCall.ClientId]; try { st.WriteLine(string.Concat ("data:", remoteCall.ToString() , "\n")); st.Flush(); } catch (Exception e) { //its very likely that the client its has been disconnected if an exception occurs return false; } return true; }
public void ToStringTest() { ClientCall target = new ClientCall(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// Sends a message to the proper client /// </summary> internal static bool SendMessage(ClientCall remoteCall, bool throwException = true) { if (remoteCall == null) { throw new ArgumentNullException("remoteCall"); } //check if the id exists if (!clientStreams.ContainsKey(remoteCall.ClientId)) { if (throwException) { throw new Exception("ClientId does not exist"); } else { return(false); } } //remove the client id from the internal list if (ConnectionsMade.Contains(remoteCall.ClientId)) { ConnectionsMade.Remove(remoteCall.ClientId); } //get the stream var st = clientStreams[remoteCall.ClientId]; lock (st) { try { //always send an empty package first string data = string.Concat("data:", "-1", "\n"); st.WriteLine(data); st.Flush(); //then send the real message data = string.Concat("data:", remoteCall.ToString(), "\n"); st.WriteLine(data); st.Flush(); ConnectionsMade.Add(remoteCall.ClientId); } catch (Exception e) { //its very likely that the client its has been disconnected if an exception occurs return(false); } } return(true); }
/// <summary> /// Sends a message to the proper client /// </summary> internal static bool SendMessage(ClientCall remoteCall, bool throwException = true) { if (remoteCall == null) throw new ArgumentNullException("remoteCall"); //check if the id exists if (!clientStreams.ContainsKey(remoteCall.ClientId)) { if (throwException) throw new Exception("ClientId does not exist"); else return false; } //remove the client id from the internal list if (ConnectionsMade.Contains(remoteCall.ClientId)) ConnectionsMade.Remove(remoteCall.ClientId); //get the stream var st = clientStreams[remoteCall.ClientId]; lock (st) { try { //always send an empty package first string data = string.Concat("data:", "-1", "\n\n"); st.WriteLine(data); st.Flush(); //then send the real message data = string.Concat("data:", remoteCall.ToString(), "\n\n"); st.WriteLine(data); st.Flush(); //always send an empty package at the end data = string.Concat("data:", "-1", "\n\n"); st.WriteLine(data); st.Flush(); ConnectionsMade.Add(remoteCall.ClientId); } catch (Exception e) { //its very likely that the client its has been disconnected if an exception occurs return false; } } return true; }