public void EmitEvent(Protocol.Event outgoingEvent) { try { //Debug.Log("Sending event " + outgoingEvent.MethodName); NetworkStream networkStream = State.Client.GetStream(); //Clear the output stream State.OutStream.SetLength(0); //Bitwig requires a 32bit integer header specifying the length of the data to follow byte[] header = BitConverter.GetBytes(outgoingEvent.CalculateSize() + 1); //Add 1 to the calculated size to account for the delimiter //The header must be in big endian format if (BitConverter.IsLittleEndian) { Array.Reverse(header, 0, header.Length); } //Write the data and the header to the stream State.OutStream.Write(header, 0, header.Length); outgoingEvent.WriteDelimitedTo(State.OutStream); //Get the data from the memory stream and write it to the network stream byte[] data = State.OutStream.ToArray(); networkStream.BeginWrite(data, 0, data.Length, new AsyncCallback(WriteCallback), data); } catch (IOException e) { Debug.LogError("Can't emit event. Not connected."); } }
public void send(Protocol.Event outgoingEvent) { try { outStream.SetLength(0); outgoingEvent.WriteDelimitedTo(outStream); byte[] data = outStream.ToArray(); sender.SendTo(data, send_end_point); } catch (Exception sendException) { Debug.Log("Dgram send error: " + sendException.Message); } }