Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using Microsoft.AspNet.SignalR.Client;
- namespace ConsoleApplication116_SignalRClient
- {
- class Program
- {
- private static void Main(string[] args)
- {
- var connection = new HubConnection("http://127.0.0.1:8088/");
- var myHub = connection.CreateHubProxy("MyHub");
- Console.WriteLine("Enter your name");
- string name = Console.ReadLine();
- connection.Start().ContinueWith(task => {
- if (task.IsFaulted)
- {
- Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException());
- }
- else
- {
- Console.WriteLine("Connected");
- myHub.On<string, Point[]>("addMessage", (s1, message) => {
- Console.WriteLine(s1 + ": " + $"move from { message[0].X},{ message[0].Y} to { message[1].X},{ message[1].Y}");
- });
- while (true)
- {
- string message = Console.ReadLine();
- if (string.IsNullOrEmpty(message))
- {
- break;
- }
- var points = new Point[]{new Point(0,0), new Point(2,2) } ;
- myHub.Invoke<string>("Send", name, points).ContinueWith(task1 => {
- if (task1.IsFaulted)
- {
- Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
- }
- else
- {
- Console.WriteLine(task1.Result);
- }
- });
- }
- }
- }).Wait();
- Console.Read();
- connection.Stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement