sta / sta/websocket-sharp

[Unity] Client is not receiving message from server.

Open
#510 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

In Unity 2018.2.16f, I'm trying to create both server and client in the editor.
I'm running the server code first:

IEnumerator ServerInit()
{
	var wssv = new WebSocketServer ("ws://127.0.0.1:9528");
	wssv.AddWebSocketService<Laputa> ("/Laputa");
	wssv.Start ();
	yield return 0;
}

public class Laputa : WebSocketBehavior
{
	protected override void OnMessage (MessageEventArgs e)
	{
		var msg = e.Data == "BALUS"
			? "I've been balused already..."
			: "I'm not available now.";

		Send (msg);
	}
}

After few seconds I'm executing the client code:

IEnumerator ClientCoroutine()
{
	using (var ws = new WebSocket("ws://127.0.0.1:9528/Laputa"))
	{
		ws.OnMessage += (sender, e) =>
			print("Laputa says: " + e.Data);

		ws.Connect();
		ws.Send("BALUS");
	}
	yield return 0;
}

But there is not message is receiving. There is no error either. Looks like nothing is happening. What am I missing?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the server and client coroutines in Unity 2018.2.16f with websocket-sharp, then trace the WebSocket Connect, Send, and OnMessage flow shown in the issue. Done means identifying why the server response is not received and confirming the client prints the reply or documenting the missing setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
game-dev, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.