Skip to content

Instantly share code, notes, and snippets.

@tocalai
Created September 5, 2019 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tocalai/6d772508bfbc3212e135d716a1fd7c11 to your computer and use it in GitHub Desktop.
Save tocalai/6d772508bfbc3212e135d716a1fd7c11 to your computer and use it in GitHub Desktop.
Demonstrate bi-direction communication between server and client.
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR;
namespace SignalR.Lab.Web.Hubs
{
public interface IEventHub
{
// here place some method(s) for message from server to client(s) (broadcast)
Task SendNoticeEventToClient(string message);
send message from server to specific group if client registered
//Task SendMessageToGroup(string group, string message);
}
public class EventHub : Hub<IEventHub>
{
// here place some method(s) for message from client to server
// subscription or un-subscription for client(s)
public Task JoinOrLeaveGroup(string group, bool check)
{
if (check)
{
return Groups.AddToGroupAsync(Context.ConnectionId, group);
}
else
{
return Groups.RemoveFromGroupAsync(Context.ConnectionId, group);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment