Advertisement
Guest User

Untitled

a guest
May 28th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class SomeClassName_socket_connect_list
  7. {
  8. public int connect_id { get; set; }
  9. public int connect_status { get; set; }
  10. public string connect_url { get; set; }
  11. public WebSocket Fun { get; set; }
  12. }
  13.  
  14.  
  15. public class EchoTest : MonoBehaviour
  16. {
  17. public int i = 0;
  18.  
  19. public List<SomeClassName_socket_connect_list> yourArray_socket_connect_list = new List<SomeClassName_socket_connect_list>();
  20.  
  21. public bool poisk_connect;
  22.  
  23. public IEnumerator StartSoket(string status, int connect_id, string url)
  24. {
  25.  
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  27.  
  28. if (status == "open")
  29. {
  30. poisk_connect = false;
  31.  
  32.  
  33. for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
  34. {
  35. if (yourArray_socket_connect_list[i].connect_id == connect_id)
  36. {
  37. poisk_connect = true;
  38.  
  39. if (yourArray_socket_connect_list[i].connect_status == 0)
  40. {
  41. StartCoroutine(yourArray_socket_connect_list[i].Fun.Connect());
  42. }
  43. }
  44. }
  45.  
  46.  
  47. if (poisk_connect == false)
  48. {
  49. yourArray_socket_connect_list.Add(new SomeClassName_socket_connect_list
  50. {
  51. connect_id = connect_id,
  52. connect_status = 1,
  53. connect_url = url,
  54. Fun = new WebSocket(new Uri(url))
  55. });
  56.  
  57. for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
  58. {
  59. if (yourArray_socket_connect_list[i].connect_id == connect_id)
  60. {
  61. StartCoroutine(yourArray_socket_connect_list[i].Fun.Connect());
  62. }
  63.  
  64. }
  65.  
  66. }
  67. }
  68.  
  69. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70.  
  71. if(status == "send")
  72. {
  73. for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
  74. {
  75. if (yourArray_socket_connect_list[i].connect_id == connect_id)
  76. {
  77. yourArray_socket_connect_list[i].Fun.SendString(UBUTUBU.Crypto.Base64Encode(url));
  78. }
  79. }
  80. }
  81.  
  82. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  83.  
  84. // if (status == "open")
  85. // {
  86. // for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
  87. // {
  88. while (true)
  89. {
  90. string reply = yourArray_socket_connect_list[i].Fun.RecvString();
  91.  
  92. if (reply != null)
  93. {
  94. Debug.Log("Received: " + UBUTUBU.Crypto.Base64Decode(reply));
  95. }
  96. if (yourArray_socket_connect_list[i].Fun.Error != null)
  97. {
  98. Debug.LogError("Error: " + yourArray_socket_connect_list[i].Fun.Error);
  99. break;
  100. }
  101. yield return 0;
  102. }
  103.  
  104. // }
  105.  
  106. // }
  107.  
  108. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  109.  
  110. if (status == "close")
  111. {
  112. for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
  113. {
  114. yourArray_socket_connect_list[i].Fun.Close();
  115. }
  116. }
  117.  
  118. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  119.  
  120. yield return null;
  121.  
  122. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement