Exemple #1
0
 protected void OnResponseReceived(ResponseReceivedEventArgs e)
 {
     if (ResponseReceived != null)
     {
         ResponseReceived(this, e);
     }
 }
Exemple #2
0
        void aClient_ResponseReceived(object sender, ResponseReceivedEventArgs e)
        {
            Dispatcher.Invoke(new Action(delegate
            {
                var values = e.Response.Split('|');

                cameraTargetRotation = Convert.ToDouble(values[0]);
            }), DispatcherPriority.Normal);
        }
Exemple #3
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                // Retrieve the state object and the client socket
                // from the asynchronous state object.
                StateObject state  = (StateObject)ar.AsyncState;
                Socket      client = state.workSocket;

                // Read data from the remote device.
                int bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    // There might be more data, so store the data received so far.
                    state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));

                    // Get the rest of the data.
                    client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                        new AsyncCallback(ReceiveCallback), state);
                }
                else
                {
                    // All the data has arrived; put it in response.
                    if (state.sb.Length > 1)
                    {
                        // Respond to the client in the UI thread to tell him that data was received
                        response = state.sb.ToString();
                        ResponseReceivedEventArgs args = new ResponseReceivedEventArgs();
                        args.Response = response;
                        OnResponseReceived(args);
                    }
                    // Signal that all bytes have been received.
                    receiveDone.Set();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }