Mehdi
Mehdi
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
Here is my new code in a github repo: https://github.com/mehdi-arch/okeygameserver
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
After the await this._hubContext.Clients.Client(connectionId).SendAsync("PiocheRequest", "Veuillez choisir la tuile à piocher (Centre ou Defausse)", requestId); it's blocking
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
I have a blocking problem here
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
public async Task<string> PiocheRequest(string connectionId)
{
var requestId = Guid.NewGuid().ToString();
var tcs = new TaskCompletionSource<string>();
await this._responsesLock.WaitAsync();
try
{
_responses[requestId] = tcs;
}
finally
{
this._responsesLock.Release();
}
await this._hubContext.Clients.Client(connectionId).SendAsync("PiocheRequest", "Veuillez choisir la tuile à piocher (Centre ou Defausse)", requestId);
await this._responsesLock.WaitAsync();
try
{
var response = await _responses[requestId].Task;
_responses.TryRemove(requestId, out _);
return response;
}
finally
{
this._responsesLock.Release();
}
}

public async Task PiocheResponse(string requestId, string response)
{
await this._responsesLock.WaitAsync();
try
{
if (_responses.TryGetValue(requestId, out var responseTask))
{
responseTask.SetResult(response);
}
}
finally
{
this._responsesLock.Release();
}

}
public async Task<string> PiocheRequest(string connectionId)
{
var requestId = Guid.NewGuid().ToString();
var tcs = new TaskCompletionSource<string>();
await this._responsesLock.WaitAsync();
try
{
_responses[requestId] = tcs;
}
finally
{
this._responsesLock.Release();
}
await this._hubContext.Clients.Client(connectionId).SendAsync("PiocheRequest", "Veuillez choisir la tuile à piocher (Centre ou Defausse)", requestId);
await this._responsesLock.WaitAsync();
try
{
var response = await _responses[requestId].Task;
_responses.TryRemove(requestId, out _);
return response;
}
finally
{
this._responsesLock.Release();
}
}

public async Task PiocheResponse(string requestId, string response)
{
await this._responsesLock.WaitAsync();
try
{
if (_responses.TryGetValue(requestId, out var responseTask))
{
responseTask.SetResult(response);
}
}
finally
{
this._responsesLock.Release();
}

}
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
Ok I found the blocking issue:
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
I don't understand why it's only happening at the third turn
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
Ok I have added the logic and at the third turn during my PiocheRequest the server is blocked:
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
Ok, I did an update of my code, with advice of @TeBeCo I used a Singleton and DI approach so here is my code re-written: But I need to order the sendings of request to the client. I thought about a Queue is this a good approach ?
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
graph TD
A[Client] -->|Connects| B((OkeyHub))
B -->|Sends lobby list| C((Client))
C -->|Chooses lobby| B
B -->|Joins lobby| D((Room))
B -->|Starts game| E((Jeu))
E -->|Distributes tiles| B
B -->|Sends game start message| C
C -->|Receives game start message| A
E -->|Requests player turn| B
B -->|Requests tile discard coordinates| A
A -->|Sends coordinates| B
B -->|Processes discard| E
E -->|Requests tile draw choice| B
B -->|Requests tile draw choice| A
A -->|Sends draw choice| B
B -->|Processes draw choice| E
E -->|Checks game end| B
B -->|Continues game loop| E
E -->|Game ends| B
B -->|Sends game end message| C
C -->|Receives game end message| A
A -->|Disconnects| B
B -->|Handles disconnection| D
D -->|Updates room status| B
graph TD
A[Client] -->|Connects| B((OkeyHub))
B -->|Sends lobby list| C((Client))
C -->|Chooses lobby| B
B -->|Joins lobby| D((Room))
B -->|Starts game| E((Jeu))
E -->|Distributes tiles| B
B -->|Sends game start message| C
C -->|Receives game start message| A
E -->|Requests player turn| B
B -->|Requests tile discard coordinates| A
A -->|Sends coordinates| B
B -->|Processes discard| E
E -->|Requests tile draw choice| B
B -->|Requests tile draw choice| A
A -->|Sends draw choice| B
B -->|Processes draw choice| E
E -->|Checks game end| B
B -->|Continues game loop| E
E -->|Game ends| B
B -->|Sends game end message| C
C -->|Receives game end message| A
A -->|Disconnects| B
B -->|Handles disconnection| D
D -->|Updates room status| B
Here is a mermaid diagram of the logic I really need
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
Here is how I call from client the methods in general: (Here PiocheRequest)
_connection.On<string, string>("PiocheRequest", async (request, requestId) =>
{
Console.WriteLine(request);
try{
var coords = Console.ReadLine();
var task = _connection.SendAsync("PiocheResponse", requestId, coords);
await task;
if(task.IsCompletedSuccessfully){
Console.WriteLine("Ok le message a ete envoye");
} else {
Console.WriteLine("On a des problemes a envoyer la tuile a piocher.");
}
} catch (Exception e){
throw;
}
});
_connection.On<string, string>("PiocheRequest", async (request, requestId) =>
{
Console.WriteLine(request);
try{
var coords = Console.ReadLine();
var task = _connection.SendAsync("PiocheResponse", requestId, coords);
await task;
if(task.IsCompletedSuccessfully){
Console.WriteLine("Ok le message a ete envoye");
} else {
Console.WriteLine("On a des problemes a envoyer la tuile a piocher.");
}
} catch (Exception e){
throw;
}
});
12 replies
CC#
Created by Mehdi on 4/10/2024 in #help
SignalR Blocking Issue: Infinite Wait When Calling a Method from Client
You have the full code of. my lobby if you want to try in local
12 replies