コード例 #1
0
        public void sender(object model, BasicDeliverEventArgs ea)
        {
            Article msg  = null;
            var     body = ea.Body;

            msg = BinFormatter.FromBytes <Article>(body);
            AppendDataGridView(msg);
        }
コード例 #2
0
        public static T ReceiveMsg <T>(Socket receiver)
        {
            byte[] length = new byte[256];

            int c    = 0;
            int step = 256;

            while (c < 256)
            {
                if (c + step > 256)
                {
                    step = 256 - c;
                }
                c += receiver.Receive(length, c, step, SocketFlags.None);
            }

            int bytesRec = BinFormatter.FromBytes <int>(length);

            byte[] bytes = new byte[bytesRec];

            int a = 0;

            step = bytesRec;
            while (a < bytesRec)
            {
                if (a + step > bytesRec)
                {
                    step = bytesRec - a;
                }
                a += receiver.Receive(bytes, a, step, SocketFlags.None);
            }
            if (bytesRec != 0)
            {
                return(BinFormatter.FromBytes <T>(bytes));
            }
            else
            {
                throw new FormatException("Серверов нет");
            }
        }