Request/Response paradigm for Websocketsharp library with using Websocket.SendAsync() and OnMessage callback function.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
We are trying to implement request/response paradigm for Websocketsharp library exactly same it works for HttpClient's request/response async behavior. We are trying to achieve it using the async callback as given in below code. We tried to get SendAsync method's OnMessage callback event to wait until the server sends the response. We are able to get the response within the scope of the SendAsync method but as soon as we come out of SendAsync scope it clears out the value of the response.
string clientResponse = null;
var response = Task.Run(() => objWSClient.SendAsync(stream, Convert.ToInt32(stream.Length), (async (completed) =>
{
if (completed)
{
clientResponse = await WSMessageSendSuccess(reqObject, callback);
// Websocket response is flushed to the console window, but when it leaves the scope, it doesn't hold the response out of the SendAsync() scope.
Console.WriteLine(clientResponse);
}
else
{
WSMessageSendFail(reqObject);
clientResponse = "Failure to send Message";
}
})));
while (response.Status != TaskStatus.RanToCompletion)
{
Task.Delay(10000).Wait();
}
response.Wait();
// As soon as we leave scope of WebSocket.SendAsync() method, it clears the client response variable value.
// variable name : clientResponse;, it also works same with static property/variable.
return clientResponse;
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SendAsync call, its OnMessage callback, and the Task.Run and polling code shown in the issue. Trace how WSMessageSendSuccess returns its response and how clientResponse is accessed after the callback completes. Done would require a documented or implemented request/response behavior that preserves the response beyond the SendAsync scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100