/// <summary> /// Creates the bbmd mac address /// </summary> private void _createBbmdMac() { var bbmdIps = Dns.GetHostAddresses(_options.BbmdHost); if (bbmdIps.Length == 0) { throw new Exception("Could not resolve '" + _options.BbmdHost + "'"); } var bbmdEp = new IPEndPoint(bbmdIps[0], _options.BbmdPort); _bbmdMac = IPUtils.IPEndPointToMac(bbmdEp); }
/// <summary> /// Called whenever a datagram is received /// </summary> /// <param name="ep">The IPEndPoint of the sending device</param> /// <param name="buffer">The buffer containing the datagram</param> /// <param name="length">The length of the received datagram</param> /// <returns>The inbound netgram to propagate, if any</returns> private void _onDatagramReceived(IPEndPoint ep, byte[] buffer, int length) { int offset = 0; BvlcHeader header = null; IBvlcMessage message = null; NetgramReceivedMessage netgram = null; Mac mac = IPUtils.IPEndPointToMac(ep); try { if (length < 4) { throw new Exception("Received datagram under 4 bytes long"); } header = new BvlcHeader(); offset = header.Deserialize(buffer, offset); if (header.Length != length) { throw new Exception("Received bvlc datagram with non-matching lengths"); } message = _createMessage(header.Function); offset = message.Deserialize(buffer, offset); lock (_lock) { netgram = _processMessage(mac, message, buffer, offset, length); } if (netgram != null && Session != null) { Session.QueueMessage(netgram); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }