private void Tick() { while (true) { if (_initReceived) { var ms = new MemoryStream(); ms.WriteByte(1); // Move request ms.Write(BitConverter.GetBytes((float)_myV.X), 0, 4); ms.Write(BitConverter.GetBytes((float)_myV.Y), 0, 4); var buf = ms.ToArray(); _socket.Send(buf, 0, buf.Length, false); } _socket.Tick(); var packet = new ReceivedSmartPacket(); while (true) { if (_socket.Receive(ref packet)) { OnReceive(packet.Buffer, packet.Offset, packet.Length, packet.EndPoint, packet.InOrder); _bufferPool.Put(packet.Buffer); } else { break; } } Thread.Sleep(100); } }
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); } }
protected override void Read() { _socket.Tick(); var packet = new ReceivedSmartPacket(); while (_socket.Receive(ref packet)) { try { ApplyState(packet.Buffer, packet.Offset, packet.Length); _bufferPool.Put(packet.Buffer); } catch (Exception e) { Console.WriteLine(e); } } }
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); }