✅ Groups & Clients in SignalR not taking requests.

I have 2 Hub tasks, 1. Connect 2. Send I save all connections that are being sent to connect with a game code, and store them in a group.. Like this:
public async Task Connect(string gameId)
{
await Groups.AddToGroupAsync(Context.ConnectionId, gameId)
}

public async Task Send(string gameId)
{
await Clients.Group(gameId).SendAsync("Testing");
}
public async Task Connect(string gameId)
{
await Groups.AddToGroupAsync(Context.ConnectionId, gameId)
}

public async Task Send(string gameId)
{
await Clients.Group(gameId).SendAsync("Testing");
}
I tried doing this, but it simply won't work? I also tried storing away a client connection ID and not go through groups, but I am not able to send any requests down to my Javascript part? It works if I use Clients.All.SendAsync(), but nothing else..?
8 Replies
Unknown User
Unknown User9h ago
Message Not Public
Sign In & Join Server To View
StilauGamer
StilauGamerOP9h ago
Its quite simple:
public class GameHub : Hub
{
public async Task Connect(string gameId)
{
await Groups.AddToGroupAsync(Context.ConnectionId, gameId)
}

public async Task Send(string gameId)
{
await Clients.Group(gameId).SendAsync("Testing");
}
}
public class GameHub : Hub
{
public async Task Connect(string gameId)
{
await Groups.AddToGroupAsync(Context.ConnectionId, gameId)
}

public async Task Send(string gameId)
{
await Clients.Group(gameId).SendAsync("Testing");
}
}
If I try sending with await Clients.All.SendAsync("Testing"); in the Send method, it works as intended...
Unknown User
Unknown User9h ago
Message Not Public
Sign In & Join Server To View
FusedQyou
FusedQyou9h ago
Did you verify Connect is called at all? The code here is valid. There's not much people can do here unless you follow the steps to debug
StilauGamer
StilauGamerOP9h ago
I actually managed to fix it? It was quite weird why it was happening? I called Connect on 1 page, and when I was redirected to a new page right after the connection ID was wrong?? It seemed like it wasn't fully started before trying to run the first "Connect" method..
Unknown User
Unknown User8h ago
Message Not Public
Sign In & Join Server To View
FusedQyou
FusedQyou7h ago
They mentioned to have fixed it unless it's a random thing?
Unknown User
Unknown User6h ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?