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(); } } }); }
private void OnGbxCallback(GbxCallbackEventArgs e) { this.EventGbxCallback?.Invoke(this, e); }