static void Main(string[] args) { Microsoft.AspNet.SignalR.Client.Connection conn = new Microsoft.AspNet.SignalR.Client.Connection("http://ipv4.fiddler:8082/group"); conn.Received += data => { Log.WriteLine(data); }; conn.Error += ex => { Log.WriteLine("An error occurred " + ex.Message); }; conn.Closed += () => { Log.WriteLine("Connection with client id " + conn.ConnectionId + " closed"); }; while (true) { switch (Console.ReadKey().Key) { case ConsoleKey.D: conn.Stop(); break; case ConsoleKey.S: conn.Send("foo:Hello").ContinueWith(task => { if (task.IsFaulted) { Log.WriteLine("Send failed " + task.Exception.GetBaseException()); } else { Log.WriteLine("Success"); } }); break; case ConsoleKey.U: Task start = conn.Start(new LongPollingTransport()).ContinueWith(task => { if (task.IsFaulted) { Log.WriteLine("Failed to start: " + task.Exception.GetBaseException()); } else { Log.WriteLine("Success! Connected with client connection id " + conn.ConnectionId); // Do more stuff here } }); break; case ConsoleKey.Q: return; default: Log.WriteLine("Unknown command"); break; } } }
static void Main(string[] args) { var connection = new Microsoft.AspNet.SignalR.Client.Connection("http://localhost:33333/Connections/ChatConnection"); connection.Received += Console.WriteLine; connection.Start().Wait(); string line; while ((line = Console.ReadLine()) != null) { connection.Send(line).Wait(); } }