Esempio n. 1
0
 public static GbxCall ReceiveCall(Socket socket, byte[] header)
 {
     if (socket.Connected)
     {
         lock (socket)
         {
             byte[] array  = new byte[4];
             byte[] array2 = new byte[4];
             if (header == null)
             {
                 socket.Receive(array);
                 socket.Receive(array2);
             }
             else
             {
                 Array.Copy(header, 0, array, 0, 4);
                 Array.Copy(header, 4, array2, 0, 4);
             }
             int    length = BitConverter.ToInt32(array, 0);
             int    handle = BitConverter.ToInt32(array2, 0);
             byte[] data   = XmlRpc.ReceiveRpc(socket, length);
             return(new GbxCall(handle, data));
         }
     }
     throw new NotConnectedException();
 }
Esempio n. 2
0
        public int AsyncRequest(string inMethodName, object[] inParams, GbxCallCallbackHandler callbackHandler)
        {
            GbxCall gbxCall = new GbxCall(inMethodName, inParams)
            {
                Handle = --this.requests
            };
            int num = XmlRpc.SendCall(this.tcpSocket, gbxCall);
            int result;

            lock (this)
            {
                if (num != 0)
                {
                    if (callbackHandler != null)
                    {
                        this.callbackList.Add(num, callbackHandler);
                    }
                    result = num;
                }
                else
                {
                    result = 0;
                }
            }
            return(result);
        }
Esempio n. 3
0
        public XmlRpcClient(EndPoint endPoint)
        {
            this.callRead     = new AutoResetEvent(false);
            this.responses    = new Hashtable();
            this.callbackList = new Hashtable();
            this.running      = true;

            if (!this.Connect(endPoint))
            {
                throw new Exception("Could not connect onto " + endPoint);
            }
            if (!this.Handshake())
            {
                throw new Exception("Handshake failed, check the server's protocol version!");
            }
            this.buffer = new byte[8];

            Task.Run(() =>
            {
                while (running)
                {
                    try
                    {
                        this.tcpSocket.Receive(this.buffer, 0, this.buffer.Length, SocketFlags.None);
                        GbxCall gbxCall = XmlRpc.ReceiveCall(this.tcpSocket, this.buffer);
                        if (gbxCall.MessageType == MessageTypes.Callback)
                        {
                            GbxCallbackEventArgs e = new GbxCallbackEventArgs(gbxCall);
                            this.OnGbxCallback(e);
                        }
                        else
                        {
                            lock (this)
                            {
                                this.responses.Add(gbxCall.Handle, gbxCall);
                            }
                            if (this.callbackList[gbxCall.Handle] != null)
                            {
                                ((GbxCallCallbackHandler)this.callbackList[gbxCall.Handle]).BeginInvoke(gbxCall, null, null);
                                this.callbackList.Remove(gbxCall.Handle);
                            }
                        }
                    }
                    catch
                    {
                        this.tcpSocket.Dispose();
                        this.OnDisconnectCallback();
                    }
                    finally
                    {
                        this.callRead.Set();
                    }
                }
            });
        }
Esempio n. 4
0
        public bool EnableCallbacks(bool inState)
        {
            GbxCall gbxCall = new GbxCall("EnableCallbacks", new object[]
            {
                inState
            })
            {
                Handle = --this.requests
            };

            return(XmlRpc.SendCall(this.tcpSocket, gbxCall) != 0);
        }
Esempio n. 5
0
        public GbxCall Request(string inMethodName, object[] inParams)
        {
            this.callRead.Reset();
            GbxCall gbxCall = new GbxCall(inMethodName, inParams)
            {
                Handle = --this.requests
            };
            int num = XmlRpc.SendCall(this.tcpSocket, gbxCall);

            do
            {
                this.callRead.WaitOne();
            }while (this.responses[num] == null && this.tcpSocket.Connected);
            if (!this.tcpSocket.Connected)
            {
                throw new NotConnectedException();
            }
            return(this.GetResponse(num));
        }