Esempio n. 1
0
        static void MainProc()
        {
            int width   = 300;
            int height  = 300;
            int counter = 0;

            while (!exitRequest)
            {
                Thread.Sleep(10);

                if (!sendComplete)
                {
                    continue;
                }
                sendComplete = false;

                byte[] buffer = new byte[width * height * 4];

                TcpProtocol.SendImageQuery query = new TcpProtocol.SendImageQuery(width, height, width, height, buffer);

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int xx = (x + counter) / 100;
                        int yy = (y + counter) / 100;

                        int  i     = 4 * (y * width + x);
                        byte color = FloatToByte(((xx + yy) % 2 == 0) ? 0.2f : 0.8f);
                        buffer[i]     = color;
                        buffer[i + 1] = color;
                        buffer[i + 2] = color;
                        buffer[i + 3] = 255;
                    }
                }

                counter += 1;

                if (counter >= int.MaxValue)
                {
                    counter = 0;
                }

                peer.Send(query);
            }
        }
Esempio n. 2
0
        private async void StartTcpMessaging(bool init)
        {
            if (init)
            {
                // 送信完了イベント
                peer.Sended += (TcpProtocol.RemoteEntity entity) => { };

                // 受信完了イベント
                peer.Received += (TcpProtocol.RemoteEntity entity) => {
                    if (entity.GetType() == typeof(TcpProtocol.SendImageQuery))
                    {
                        TcpProtocol.SendImageQuery query = (TcpProtocol.SendImageQuery)entity;
                        UpdateImage(
                            query.ImageBuffer,
                            query.BufferWidth, query.BufferHeight,
                            query.Width, query.Height);
                    }
                };

                await peer.Accept(IPAddress.Any, 9099);
            }
            else
            {
                await peer.Accept();
            }

            Debug.WriteLine("通信開始");

            await peer.Start();

            Debug.WriteLine("通信終了");

            ClearRuntimeImage();

            if (!isExitRequested)
            {
                // 再起動
                StartTcpMessaging(false);
            }
        }