Beispiel #1
0
        public void Notify <T>(T data)
        {
            ssendClient.Connect(IPAddress.Broadcast, serverPort);

            var buf = ProtocolFactory.CreateProtocol(data, host == 0 ? _ip : host);

            ssendClient.Send(buf, buf.Length);
        }
Beispiel #2
0
        public static byte[] CreateProtocol <T>(T data, int host)
        {
            var attrs = typeof(T).GetCustomAttributes(typeof(ProtocolIdAttribute), false);
            var pid   = attrs[0] as ProtocolIdAttribute;

            var p = ProtocolFactory.CreateProtocol(pid.id, host);

            using (var stream = new MemoryStream())
            {
                stream.Position = 0;
                ProtoBuf.Serializer.Serialize(stream, data);
                stream.Flush();
                p.data = stream.ToArray();

                stream.Seek(0, SeekOrigin.Begin);
                ProtoBuf.Serializer.Serialize(stream, p);
                stream.Flush();

                return(stream.ToArray());
            }
        }
Beispiel #3
0
        public void Host(int type)
        {
            if (this.host != 0)
            {
                return;
            }

            this.type = type;

            var client = bsendClient;

            client.Connect(IPAddress.Broadcast, broadcastPort);

            BroadcastProtocol data = new BroadcastProtocol();

            data.ip   = _ip;
            data.port = serverPort;
            data.type = type;

            var buf = ProtocolFactory.CreateProtocol(data, 0);

            client.Send(buf, buf.Length);
        }