Browser and Server Communication Problem - Server only receive One text?

Open
#341 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp, unity
Domain
networking

Research direction

Reproduce the report with the EchoTest client and IOWebSocket/Echo server code, comparing standalone Unity and Firefox HTML5 builds. Start by tracing the WebSocket connection and message loop; done means identifying why only the first message arrives and verifying the behavior after the correction.

Written by the indexing model from the issue text.

Description

I try to build the website and communicate with Server (not web server), by using unity3D.
The problem is that, when i run both code on unity3d (one is client, other one Server). Both can send/ receive test string very well.
[client side will send text:0,1,2,3,4,5,....][client side receive text:123,123]
[server side will send test:123,123. if server receive client side data][server side receive text:0,1,2,3,4,5,....]

But when i build the [website(client) code] to html5 by using unity3D and run on Firefox browser. The server only receive One text data.
[server side receive the text:0]
[client side no receive]

This is website(client) code:

public class EchoTest : MonoBehaviour {

// Use this for initialization
IEnumerator Start () {
    WebSocket w = new WebSocket(new Uri("ws://127.0.0.1:3000")); 
    yield return StartCoroutine(w.Connect());
    w.SendString("0");
    int i = 0;
    while (true)
	{
		string reply = w.RecvString();
		if (reply != null)
		{
			Debug.Log ("Received: "+reply);
			w.SendString(""+i++);
		}
		if (w.error != null)
		{
			Debug.LogError ("Error: "+w.error);
			break;
		}
		yield return 0;
	}
    w.Close();
}

}

This is Server code:

public class IOWebSocket : MonoBehaviour
{

private static int i = 0;
WebSocketServer server;

void Start()
{
    server = new WebSocketServer(3000);
    server.AddWebSocketService<Echo>("/");
    server.Start();     
}

void OnDestroy()
{
    server.Stop();
    server = null;
}

}
// Update is called once per frame
public class Echo : WebSocketBehavior
{
protected override void OnMessage(MessageEventArgs e)
{
Sessions.Broadcast("123");
Debug.Log(System.Text.Encoding.Default.GetString(e.RawData));
}
}

I need some help,plz

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

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.

More from sta/websocket-sharp

All issues in sta/websocket-sharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.