Created
November 25, 2017 23:19
-
-
Save radu-matei/068b6615beab5d1fdd251d0b56427c79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.SignalR.Client; | |
namespace console_client | |
{ | |
class Program | |
{ | |
private static HubConnection _connection; | |
static void Main(string[] args) | |
{ | |
StartConnectionAsync(); | |
_connection.On<string, string>("broadcastMessage", (name, message) => | |
{ | |
Console.WriteLine($"{name} said: {message}"); | |
}); | |
Console.ReadLine(); | |
DisposeAsync(); | |
} | |
public static async Task StartConnectionAsync() | |
{ | |
_connection = new HubConnectionBuilder() | |
.WithUrl("http://localhost:5000/chat") | |
.WithConsoleLogger() | |
.Build(); | |
await _connection.StartAsync(); | |
} | |
public static async Task DisposeAsync() | |
{ | |
await _connection.DisposeAsync(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment