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 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 {
}
This is Server code:
public class IOWebSocket : MonoBehaviour {
} // 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