コード例 #1
0
        void Update()
        {
            //byte
            byte[][] bytes = null;
            lock (binaryQueue)
            {
                bytes = binaryQueue.ToArray();
                binaryQueue.Clear();
            }

            if (handle != null)
            {
                foreach (var b in bytes)
                {
                    handle.OnRawBytes(b);
                }
            }

            //string
            string[] messages = null;
            lock (messageQueue)
            {
                messages = messageQueue.ToArray();
                messageQueue.Clear();
            }

            if (handle != null)
            {
                foreach (var message in messages)
                {
                    handle.OnRawString(message);
                }
            }
        }
コード例 #2
0
ファイル: UDPConnection.cs プロジェクト: MichaelVZ777/Test
        void Update()
        {
            foreach (var packetInfo in udp.ReceiveAll())
            {
                if (handle != null)
                {
                    handle.OnRawBytes(packetInfo.data);
                    handle.OnRawString(Encoding.UTF8.GetString(packetInfo.data));
                }
            }

            if (!udp.isRunning && autoRestart)
            {
                udp.StartListener();
            }
        }
コード例 #3
0
ファイル: TCPConnection.cs プロジェクト: MichaelVZ777/Test
        void Update()
        {
            if (status == Status.Disconnected && autoConnect)
            {
                Connect();
            }


            string[] messages = null;
            lock (messageQueue)
            {
                messages = messageQueue.ToArray();
                messageQueue.Clear();
            }

            if (handle != null)
            {
                foreach (var message in messages)
                {
                    handle.OnRawString(message);
                }
            }

            if (status != lastStatus)
            {
                lastStatus = status;
                if (handle != null)
                {
                    switch (status)
                    {
                    case Status.Connected:
                        handle.OnConnected();
                        break;

                    case Status.Connecting:
                        handle.OnConnecting();
                        break;

                    case Status.Disconnected:
                        handle.OnDisconencted();
                        break;
                    }
                }
            }
        }