예제 #1
0
        public void CallWithputReply(RpcCallMessage callProcedure)
        {
            CallMessage = callProcedure;
            byte[] mes      = callProcedure.ToBytes();
            byte[] finalmes = new byte[sizeof(uint) + mes.Length];
            Buffer.BlockCopy(NetUtils.ToBigEndianBytes(xid), 0, finalmes, 0, 4);
            Buffer.BlockCopy(mes, 0, finalmes, 4, mes.Length);
            switch (ConnectionType)
            {
            case ProtocolType.Tcp:
                if (!RpcSocket.Connected)
                {
                    RpcSocket.Connect(RemoteEndPoint);
                }
                RpcSocket.Send(finalmes);
                break;

            case ProtocolType.Udp:
                RpcSocket.SendTo(finalmes, RemoteEndPoint);
                break;

            default:
                throw new Exception(ConnectionType.ToString() +
                                    " protocol have not realization of function Call().");
            }
        }
예제 #2
0
        public Dictionary <EndPoint, RpcReplyMessage> Call(RpcCallMessage callProcedure)
        {
            Dictionary <EndPoint, RpcReplyMessage> replies = new Dictionary <EndPoint, RpcReplyMessage>();

            CallMessage = callProcedure;
            bool     waitReplies = ConnectionType == ProtocolType.Tcp ? false : true;
            EndPoint ep          = new IPEndPoint(IPAddress.Any, 111);

            byte[] mes      = callProcedure.ToBytes();
            byte[] finalmes = new byte[sizeof(uint) + mes.Length];
            Buffer.BlockCopy(NetUtils.ToBigEndianBytes(xid), 0, finalmes, 0, 4);
            Buffer.BlockCopy(mes, 0, finalmes, 4, mes.Length);
            switch (ConnectionType)
            {
            case ProtocolType.Tcp:
                if (!RpcSocket.Connected)
                {
                    RpcSocket.Connect(RemoteEndPoint);
                }
                RpcSocket.Send(finalmes);
                break;

            case ProtocolType.Udp:
                RpcSocket.SendTo(finalmes, RemoteEndPoint);
                break;

            default:
                throw new Exception(ConnectionType.ToString() +
                                    " protocol have not realization of function Call().");
            }
            do
            {
                try
                {
                    byte[] buff    = new byte[1024];
                    int    recSize = RpcSocket.ReceiveFrom(buff, ref ep);
                    if (!CheckReply((IPEndPoint)ep, buff))
                    {
                        continue;
                    }
                    recSize -= sizeof(uint);
                    byte[] nbuff = new byte[recSize];
                    Buffer.BlockCopy(buff, sizeof(uint), nbuff, 0, recSize);
                    if (((IPEndPoint)ep).Port == RemoteEndPoint.Port)
                    {
                        replies.Add(ep, new RpcReplyMessage(nbuff));
                    }
                }
                catch (SocketException)
                {
                    waitReplies = false;
                }
            }while (waitReplies);
            return(replies);
        }