Ejemplo n.º 1
0
    IEnumerator TestSocket()
    {
        manager.AddMessageEvent(
            (sender, e) =>
        {
            recieveTime = DateTime.Now.Ticks;
            print($"It took {(recieveTime - sendTime) / 10000} milliseconds\n To recieve \"{e.Data}\"");
        }
            );

        string words =
            "                                                                                                                                                                \n" +
            "                     ``./oo:`                         `/o/:.                                                                                                    \n" +
            "            smmhshhdmmMMMMMMm/                         +dMMMms-                                               ,ee,                                              \n" +
            "            -hMMMMhooo+/oMMMM/                           /MMMMh                                               oNMmdhyyyy:                                       \n" +
            "             `yMMMy     `MMMd`                            mMMMh                                                 ``----```                                       \n" +
            "              `dMMN..--:+MMM+           .+ydmNNmdy:`      mMMMh                                         +ss+++++++osyhhmNNNh:                                   \n" +
            "               :MMMmmNNNNNmms          :mMMNhoohNMMm/     dMMMh ,e,                                     `o:/`` ,/mmddhhy;,  `                                   \n" +
            "                        ...,.,        `dMMM      mMMM-    hMMMNyhhddo   -sdNMMMMNdy/.       ::.              .mMMNy++smMMd.          -sdNMMMMNdy/.       ::.    \n" +
            "    oddhhhhhdddmmmddmmNNMNmmmNNNN+     .yNMMmhhdNMMNo     yMMMh        /NMNho:/ohmMMNds//oymMMh`             +MMMs    :MMMo         /NMNho:/ohNMMNds//oymMMy    \n" +
            "    `-ohmNNmdhs+/:--..sMMNh:..--.        -+hdmmmdy+.      yMMMh`.-..   `//-      .:sdmNMMNNmh+`              `hMMNyo+smMMm-         `//-      .:sdmNMMNNmh+`    \n" +
            "                      :MMMM+                ````          yMMMNmNNNms                `.---.`                  `:smMMMNmdo.                        `.---.`       \n" +
            "                      -MMMM:                              sMMMd+osss/                                            oMMMNs`                                        \n" +
            "                      .NMMM-                              /MMMs                                    `-.           .+MMMh   ,,+ss.                                \n" +
            "                       dMMN`                              .MMN-                                    yNNNNNNNmmmmNNmNNNNNNNMMMMMMm-                               \n" +
            "                       sMMs                               `mMo                                     `-+hmmmhyso+:::-......-::+oo:                                \n" +
            "                       sMo                                .Ns                                          ```                                                      \n" +
            "                       --                                 `-                                                                                                    \n" +
            "                                                                                                                                                                \n";

        for (; !stopSending;)
        {
            ConnectionManager.PutMessage(words, true, (error) => { sendTime = DateTime.Now.Ticks; });
            yield return(new WaitForSeconds(10f));
        }
        yield break;
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        if (inputMessageQueue is null)
        {
            inputMessageQueue = new Queue <string>();
        }
        if (outputMessageQueue is null)
        {
            outputMessageQueue = new Queue <PacketInfo>();
        }

        if (!established)
        {
            terminated = false;
            globalSocket.SocketInit("ws://hojoondev.kro.kr:3001", true);
            globalSocket.AddOpenEvent((sender, e) => { print("Established!"); established = true; });
            globalSocket.AddMessageEvent(
                (sender, e) =>
            {
                string[] splitTokens = { "brodcast: " };
                string message;
                if (e.Data.Contains("brodcast:") == false)
                {
                    message = e.Data;
                }
                else
                {
                    message = e.Data.Split(splitTokens, StringSplitOptions.RemoveEmptyEntries)[0];
                }
                inputMessageQueue.Enqueue(message);
            }
                );
            globalSocket.AddCloseEvent((sender, e) => { print("Connection Closed"); });
        }
        StartCoroutine(GlobalSocketLoop());
    }