Esempio n. 1
0
 /// <summary>
 /// Alternative creator for clients
 /// </summary>
 /// <param name="_ClientReceiveTimeout"></param>
 public Client(int _ClientReceiveTimeout)
 {
     clientPipe           = null;
     proxy                = ProxyHelper.GetInstance <T>(OnMethodCallback);
     bConnected           = false;
     ClientReceiveTimeout = _ClientReceiveTimeout;
 }
Esempio n. 2
0
        /// <summary>
        /// Connects with a spesified timeout value
        /// 0 = infinity
        /// </summary>
        /// <param name="Pipename"></param>
        /// <param name="Timeout"></param>
        public void Connect(string Pipename, int Timeout)
        {
            clientPipe = new ClientPipe(".", Pipename, p => p.StartMessageReaderAsync());

            clientPipe.DataReceived += (sndr, args) =>
            {
                ClientPipe sender = sndr as ClientPipe;
                OnMessageReceived(sender, args.Data);
            };

            //Disconnect event trigger, sets connected state to false
            clientPipe.Disconnect += (sndr, args) =>
            {
                bConnected = false;
                ClientDisconnected?.Invoke(this, new EventArgs());
            };

            clientPipe.Connect(Timeout);
            bConnected = true;
        }
Esempio n. 3
0
 /// <summary>
 /// Since the Pipes used is full duplex, the received messages are through other threads
 /// The OnMethodCallback needs this info, it waits for the responseEvent to be set
 /// </summary>
 /// <param name="clientPipe"></param>
 /// <param name="bytes"></param>
 private void OnMessageReceived(ClientPipe clientPipe, byte[] bytes)
 {
     responseJson = Encoding.ASCII.GetString(bytes);
     responseEvent.Set();
 }