public static void SendCmdCar(Socket Scksender, int AcelX, int AcelY, int AcelZ, byte[] Buttons, byte IdPlayer) { // Encode the data string into a byte array. byte[] msg = new byte[1 + 1 + 12 + 3]; byte[] OutMsg = null; int bytesSent = 0; msg[0] = (byte)CmdNetwork.DATA_ACEL; msg[1] = IdPlayer; HelpConv.FillByteArray(ref msg, 2, BitConverter.GetBytes(AcelX)); HelpConv.FillByteArray(ref msg, 6, BitConverter.GetBytes(AcelY)); HelpConv.FillByteArray(ref msg, 10, BitConverter.GetBytes(AcelZ)); msg[14] = Buttons[0]; msg[15] = Buttons[1]; msg[16] = Buttons[2]; OutMsg = BuildMsg("ControlCarNetworkObject", msg); //Envio longitud bytesSent = Scksender.Send(BitConverter.GetBytes(OutMsg.Length)); //Hago pausa System.Threading.Thread.Sleep(100); // Send the data through the socket. bytesSent = Scksender.Send(OutMsg); }
public static byte[] BuildMsg(string IdNetObj, byte[] Datos) { byte[] Outmsg = new byte[Datos.Length + IdNetObj.Length + 3]; byte[] id = HelpConv.ConvertToByte(IdNetObj); Outmsg[0] = Convert.ToByte(Outmsg.Length - 2); Outmsg[1] = 0x00; Outmsg[2] = Convert.ToByte(id.Length); id.CopyTo(Outmsg, 3); Datos.CopyTo(Outmsg, 3 + id.Length); return(Outmsg); }