Esempio n. 1
0
        protected override void Init()
        {
            var smartSock = new SmartSock(_bufferPool, new ThreadSock(_bufferPool, AddressFamily.InterNetwork, new LoggerStub()), _soc);

            _socket = new ThreadSafeSmartSock(smartSock);
            _socket.Connect(IPAddress.Loopback, 2345);
            var receivedPacket = new ReceivedSmartPacket();

            while (_socket.State == PixocketState.Connecting)
            {
                _socket.Tick();
                _socket.Receive(ref receivedPacket);
            }
        }
Esempio n. 2
0
        public void Connect(float x, float y)
        {
            var smartSock = new SmartSock(_bufferPool, new ThreadSock(_bufferPool, AddressFamily.InterNetwork, new LoggerStub()), this);

            _socket = new ThreadSafeSmartSock(smartSock);
            // Todo: pass address from command line
            _socket.Connect(IPAddress.Loopback, 2345);
            var receivedPacket = new ReceivedSmartPacket();

            while (_socket.State == PixocketState.Connecting)
            {
                _socket.Tick();
                _socket.Receive(ref receivedPacket);
            }

            var ms = new MemoryStream();

            ms.WriteByte(0);  // Init request packet

            byte  red   = (byte)_rnd.Next(0, byte.MaxValue + 1);
            byte  green = (byte)_rnd.Next(0, byte.MaxValue + 1);
            byte  blue  = (byte)_rnd.Next(0, byte.MaxValue + 1);
            Brush brush = new SolidColorBrush(Color.FromArgb(255, red, green, blue));

            ms.WriteByte(red);
            ms.WriteByte(green);
            ms.WriteByte(blue);

            ms.Write(BitConverter.GetBytes(x), 0, 4);
            ms.Write(BitConverter.GetBytes(y), 0, 4);

            var sendBuffer = ms.ToArray();

            _myV   = new Vertex();
            _myV.X = x;
            _myV.Y = y;
            _myV.C = brush;

            _socket.Send(sendBuffer, 0, sendBuffer.Length, true);
        }