Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- public class SomeClassName_socket_connect_list
- {
- public int connect_id { get; set; }
- public int connect_status { get; set; }
- public string connect_url { get; set; }
- public WebSocket Fun { get; set; }
- }
- public class EchoTest : MonoBehaviour
- {
- public int i = 0;
- public List<SomeClassName_socket_connect_list> yourArray_socket_connect_list = new List<SomeClassName_socket_connect_list>();
- public bool poisk_connect;
- public IEnumerator StartSoket(string status, int connect_id, string url)
- {
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if (status == "open")
- {
- poisk_connect = false;
- for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
- {
- if (yourArray_socket_connect_list[i].connect_id == connect_id)
- {
- poisk_connect = true;
- if (yourArray_socket_connect_list[i].connect_status == 0)
- {
- StartCoroutine(yourArray_socket_connect_list[i].Fun.Connect());
- }
- }
- }
- if (poisk_connect == false)
- {
- yourArray_socket_connect_list.Add(new SomeClassName_socket_connect_list
- {
- connect_id = connect_id,
- connect_status = 1,
- connect_url = url,
- Fun = new WebSocket(new Uri(url))
- });
- for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
- {
- if (yourArray_socket_connect_list[i].connect_id == connect_id)
- {
- StartCoroutine(yourArray_socket_connect_list[i].Fun.Connect());
- }
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if(status == "send")
- {
- for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
- {
- if (yourArray_socket_connect_list[i].connect_id == connect_id)
- {
- yourArray_socket_connect_list[i].Fun.SendString(UBUTUBU.Crypto.Base64Encode(url));
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // if (status == "open")
- // {
- // for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
- // {
- while (true)
- {
- string reply = yourArray_socket_connect_list[i].Fun.RecvString();
- if (reply != null)
- {
- Debug.Log("Received: " + UBUTUBU.Crypto.Base64Decode(reply));
- }
- if (yourArray_socket_connect_list[i].Fun.Error != null)
- {
- Debug.LogError("Error: " + yourArray_socket_connect_list[i].Fun.Error);
- break;
- }
- yield return 0;
- }
- // }
- // }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if (status == "close")
- {
- for (int i = 0; i < yourArray_socket_connect_list.Count; i++)
- {
- yourArray_socket_connect_list[i].Fun.Close();
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- yield return null;
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement