Wait for ws until execute return
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I am trying to run a ws client example:
my function is below:
public static Tuple<int, string> wingm(string userName, string extrastr, string)
{
var ws = new WebSocket("wss://just.mywssgame.uk:7002/");
using (ws)
{
//ws.Connect();
String returnResultJSON = "";
ws.OnMessage += (sender, e) =>
{
dynamic messageJSONresponse = JsonConvert.DeserializeObject(e.Data);
if (Convert.ToString(messageJSONresponse.type) == "playerone")
{
returnResultJSON = Convert.ToString(messageJSONresponse);
Console.WriteLine(returnResultJSON);
}
}
};
//we begin here
ws.Connect();
ws.Send(userName);
Console.ReadKey(true);
}
return Tuple.Create("0", returnResultJSON);
}
I then call above function in an console application:
Tuple<int, string> tempResult = wingm("somnam", "");
Console.WriteLine(tempResult.Item1.ToString());
Console.WriteLine(tempResult.Item2.ToString());
But the websocket executes in a seperate thread, so the function returns an empty string as it's not set yet.
Is there a way to run above ws client example so that the function waits on the websocket to close?
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
The example is contained in the issue body; start by tracing wingm from ws.Connect() and ws.Send() through the OnMessage callback and return. Define the completion condition as the received response or socket close, then verify that the returned tuple is populated only after that condition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100