private static void Listen() { //Debug.Log("InputService: Ready to receive data"); while (true) { //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); //Console.WriteLine("receiveBytes length: " + receiveBytes.Length); //#define OI_READBUF(type, buf, offset, val) val = *((type*)&buf[offset]); offset += sizeof(type); MemoryStream ms = new MemoryStream(); ms.Write(receiveBytes, 0, receiveBytes.Length); BinaryReader reader = new BinaryReader(ms); omicronConnector.EventData ed = new omicronConnector.EventData(); reader.BaseStream.Position = 0; ed.timestamp = reader.ReadUInt32(); ed.sourceId = reader.ReadUInt32(); ed.serviceId = reader.ReadInt32(); ed.serviceType = (EventBase.ServiceType)reader.ReadUInt32(); ed.type = reader.ReadUInt32(); ed.flags = reader.ReadUInt32(); if (ed.type != 3) { Console.WriteLine(ed.type); Console.WriteLine(ed.flags); Console.WriteLine("---"); } ed.posx = reader.ReadSingle(); ed.posy = reader.ReadSingle(); ed.posz = reader.ReadSingle(); ed.orw = reader.ReadSingle(); ed.orx = reader.ReadSingle(); ed.ory = reader.ReadSingle(); ed.orz = reader.ReadSingle(); ed.extraDataType = (omicron.EventBase.ExtraDataType)reader.ReadUInt32(); ed.extraDataItems = reader.ReadUInt32(); ed.extraDataMask = reader.ReadUInt32(); ed.extraData = reader.ReadBytes(EventData.ExtraDataSize); listener.onEvent(ed); } }// Listen()
}// Listen() public static EventData ByteArrayToEventData(byte[] receiveBytes) { MemoryStream ms = new MemoryStream(); ms.Write(receiveBytes, 0, receiveBytes.Length); BinaryReader reader = new BinaryReader(ms); omicronConnector.EventData ed = new omicronConnector.EventData(); reader.BaseStream.Position = 0; ed.timestamp = reader.ReadUInt32(); ed.sourceId = reader.ReadUInt32(); ed.serviceId = reader.ReadInt32(); ed.serviceType = (EventBase.ServiceType)reader.ReadUInt32(); ed.type = reader.ReadUInt32(); ed.flags = reader.ReadUInt32(); if (ed.type != 3) { Console.WriteLine(ed.type); Console.WriteLine(ed.flags); Console.WriteLine("---"); } ed.posx = reader.ReadSingle(); ed.posy = reader.ReadSingle(); ed.posz = reader.ReadSingle(); ed.orw = reader.ReadSingle(); ed.orx = reader.ReadSingle(); ed.ory = reader.ReadSingle(); ed.orz = reader.ReadSingle(); ed.extraDataType = (omicron.EventBase.ExtraDataType)reader.ReadUInt32(); ed.extraDataItems = reader.ReadUInt32(); ed.extraDataMask = reader.ReadUInt32(); ed.extraData = reader.ReadBytes(EventData.ExtraDataSize); return(ed); }
private static void Listen() { //Debug.Log("InputService: Ready to receive data"); while (true) { //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); //Console.WriteLine("receiveBytes length: " + receiveBytes.Length); //#define OI_READBUF(type, buf, offset, val) val = *((type*)&buf[offset]); offset += sizeof(type); MemoryStream ms = new MemoryStream(); ms.Write(receiveBytes, 0, receiveBytes.Length); BinaryReader reader = new BinaryReader(ms); omicronConnector.EventData ed = new omicronConnector.EventData(); reader.BaseStream.Position = 0; ed.timestamp = reader.ReadUInt32(); ed.sourceId = reader.ReadUInt32(); ed.serviceId = reader.ReadInt32(); ed.serviceType = (EventBase.ServiceType)reader.ReadUInt32(); ed.type = reader.ReadUInt32(); ed.flags = reader.ReadUInt32(); if (ed.type != 3) { Console.WriteLine(ed.type); Console.WriteLine(ed.flags); Console.WriteLine("---"); } ed.posx = reader.ReadSingle(); ed.posy = reader.ReadSingle(); ed.posz = reader.ReadSingle(); ed.orw = reader.ReadSingle(); ed.orx = reader.ReadSingle(); ed.ory = reader.ReadSingle(); ed.orz = reader.ReadSingle(); ed.extraDataType = (omicron.EventBase.ExtraDataType)reader.ReadUInt32(); ed.extraDataItems = reader.ReadUInt32(); ed.extraDataMask = reader.ReadUInt32(); ed.extraData = reader.ReadBytes(EventData.ExtraDataSize); listener.onEvent(ed); } }
public static EventData ByteArrayToEventData(byte[] receiveBytes) { MemoryStream ms = new MemoryStream(); ms.Write(receiveBytes, 0, receiveBytes.Length); BinaryReader reader = new BinaryReader(ms); omicronConnector.EventData ed = new omicronConnector.EventData(); reader.BaseStream.Position = 0; ed.timestamp = reader.ReadUInt32(); ed.sourceId = reader.ReadUInt32(); ed.serviceId = reader.ReadInt32(); ed.serviceType = (EventBase.ServiceType)reader.ReadUInt32(); ed.type = reader.ReadUInt32(); ed.flags = reader.ReadUInt32(); if (ed.type != 3) { Console.WriteLine(ed.type); Console.WriteLine(ed.flags); Console.WriteLine("---"); } ed.posx = reader.ReadSingle(); ed.posy = reader.ReadSingle(); ed.posz = reader.ReadSingle(); ed.orw = reader.ReadSingle(); ed.orx = reader.ReadSingle(); ed.ory = reader.ReadSingle(); ed.orz = reader.ReadSingle(); ed.extraDataType = (omicron.EventBase.ExtraDataType)reader.ReadUInt32(); ed.extraDataItems = reader.ReadUInt32(); ed.extraDataMask = reader.ReadUInt32(); ed.extraData = reader.ReadBytes(EventData.ExtraDataSize); return ed; }