Ejemplo n.º 1
0
        byte[] Serialize <T>(T message) where T : Message
        {
            var stream = new MemoryStream();

            var writer = new BinaryWriter(stream);

            try
            {
                writer.Write(MessageRegistrar.KeyFromMessageType <T>());
                message.Save(writer);
                writer.Flush();

                if (stream.Length > Constants.MAX_UDP_SIZE)
                {
                    throw new ArgumentException("Message size exceeded maximum length");
                }
            }
            finally
            {
#if WINDOWS_UWP
                writer.Dispose();
#else
                writer.Close();
#endif
            }
            return(stream.ToArray());
        }
Ejemplo n.º 2
0
 // Note: 239.0.0.0 is the start of the UDP multicast addresses reserved for
 // private use.
 // Note: 49152 is the result I get out of executing;
 //      netsh int ipv4 show dynamicport udp
 // on Windows 10.
 public MessageService(
     MessageRegistrar messageRegistrar,
     string localNetworkAddress,
     string multicastAddress = "239.0.0.0",
     int multicastPort       = 49152)
 {
     //if (messageRegistrar == null)
     //{
     //    throw new ArgumentNullException("MessageRegistrar is null");
     //}
     this.messageRegistrar    = messageRegistrar;
     this.localNetworkAddress = IPAddress.Parse(localNetworkAddress);
     this.multicastEndpoint   = new IPEndPoint(IPAddress.Parse(multicastAddress), multicastPort);
 }