EchoTest.cs 628 B

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. //example of websockets
  5. /*
  6. public class EchoTest : MonoBehaviour {
  7. private void Log(String str)
  8. {
  9. Debug.Log(str);
  10. }
  11. // Use this for initialization
  12. IEnumerator Start () {
  13. WebSocket w = new WebSocket(new Uri("ws://localhost/WebSocketsTest"));
  14. yield return StartCoroutine(w.Connect());
  15. w.SendString("Hi!");
  16. int i=0;
  17. while (true)
  18. {
  19. string reply = w.RecvString();
  20. if (reply != null) {
  21. w.SendString ("Hi:" + i++);
  22. }
  23. if (w.error != null)
  24. {
  25. //Log ("Error: "+w.error);
  26. break;
  27. }
  28. yield return 0;
  29. }
  30. w.Close();
  31. }
  32. }
  33. */