Ejemplo n.º 1
0
 public static int SendCall(Socket socket, GbxCall call)
 {
     if (socket.Connected)
     {
         lock (socket)
         {
             try
             {
                 byte[] bytes  = Encoding.UTF8.GetBytes(call.Xml);
                 byte[] bytes2 = BitConverter.GetBytes(bytes.Length);
                 byte[] bytes3 = BitConverter.GetBytes(call.Handle);
                 byte[] array  = new byte[bytes2.Length + bytes3.Length + bytes.Length];
                 Array.Copy(bytes2, 0, array, 0, bytes2.Length);
                 Array.Copy(bytes3, 0, array, 4, bytes3.Length);
                 Array.Copy(bytes, 0, array, 8, bytes.Length);
                 socket.Send(array);
                 int result = call.Handle;
                 return(result);
             }
             catch
             {
                 int result = 0;
                 return(result);
             }
         }
     }
     throw new NotConnectedException();
 }
Ejemplo 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);
        }
Ejemplo 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();
                    }
                }
            });
        }
Ejemplo 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);
        }
Ejemplo 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));
        }
 public GbxCallbackEventArgs(GbxCall response)
 {
     this.Response = response;
 }