Advertisement
Guest User

Untitled

a guest
May 21st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using Microsoft.AspNet.SignalR.Client;
  4.  
  5. namespace ConsoleApplication116_SignalRClient
  6. {
  7. class Program
  8. {
  9. private static void Main(string[] args)
  10. {
  11. var connection = new HubConnection("http://127.0.0.1:8088/");
  12. var myHub = connection.CreateHubProxy("MyHub");
  13.  
  14. Console.WriteLine("Enter your name");
  15. string name = Console.ReadLine();
  16.  
  17. connection.Start().ContinueWith(task => {
  18. if (task.IsFaulted)
  19. {
  20. Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException());
  21. }
  22. else
  23. {
  24. Console.WriteLine("Connected");
  25.  
  26. myHub.On<string, Point[]>("addMessage", (s1, message) => {
  27. Console.WriteLine(s1 + ": " + $"move from { message[0].X},{ message[0].Y} to { message[1].X},{ message[1].Y}");
  28. });
  29.  
  30. while (true)
  31. {
  32. string message = Console.ReadLine();
  33.  
  34. if (string.IsNullOrEmpty(message))
  35. {
  36. break;
  37. }
  38. var points = new Point[]{new Point(0,0), new Point(2,2) } ;
  39. myHub.Invoke<string>("Send", name, points).ContinueWith(task1 => {
  40. if (task1.IsFaulted)
  41. {
  42. Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
  43. }
  44. else
  45. {
  46. Console.WriteLine(task1.Result);
  47. }
  48. });
  49. }
  50. }
  51.  
  52. }).Wait();
  53.  
  54. Console.Read();
  55. connection.Stop();
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement