예제 #1
0
        public UdpSocketSender(string address, int port)
        {
            _state  = new UdpState();
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _socket.Connect(IPAddress.Parse(address), port);

            _props = typeof(Report).GetProperties();
        }
예제 #2
0
        public void Send(Report report)
        {
            byte[] data = report.SerializeToByteArray();

            _socket.BeginSend(data, 0, data.Length, SocketFlags.None, (ar) =>
            {
                UdpState so = (UdpState)ar.AsyncState;
                int bytes   = _socket.EndSend(ar);
                Console.WriteLine("SEND: {0}, {1}", bytes, report.Var1);
            }, _state);
        }