Skip to content

Instantly share code, notes, and snippets.

@radu-matei
Created November 25, 2017 23:19
Show Gist options
  • Save radu-matei/068b6615beab5d1fdd251d0b56427c79 to your computer and use it in GitHub Desktop.
Save radu-matei/068b6615beab5d1fdd251d0b56427c79 to your computer and use it in GitHub Desktop.
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