void gotResponse(object sender, ResponseReceivedEventArgs e) { if (e.isError) { //(e.response); } else { //textBlock5.Text = e.response; } }
void gotList(object sender, ResponseReceivedEventArgs e) { if (e.isError) { //(e.response); } else { textBlock5.Text = e.response; //Console.Write(e.response); } }
// Invoke the ResponseReceived event protected void OnResponseReceived(ResponseReceivedEventArgs e) { if (ResponseReceived != null) ResponseReceived(this, e); }
// Called when a SendAsync operation completes private void ProcessSend(SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { //Read data sent from the server Socket sock = e.UserToken as Socket; sock.ReceiveAsync(e); } else { ResponseReceivedEventArgs args = new ResponseReceivedEventArgs(); args.response = e.SocketError.ToString(); args.isError = true; OnResponseReceived(args); } }
// Called when a ReceiveAsync operation completes private void ProcessReceive(SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { // Received data from server string dataFromServer = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred); Socket sock = e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send); sock.Close(); // Respond to the client in the UI thread to tell him that data was received System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { ResponseReceivedEventArgs args = new ResponseReceivedEventArgs(); args.response = dataFromServer; OnResponseReceived(args); }); } else { throw new SocketException((int)e.SocketError); } }
// Called when a ConnectAsync operation completes private void ProcessConnect(SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { // Successfully connected to the server // Send data to the server byte[] buffer = Encoding.UTF8.GetBytes(dataIn + "<EOF>"); e.SetBuffer(buffer, 0, buffer.Length); Socket sock = e.UserToken as Socket; sock.SendAsync(e); } else { ResponseReceivedEventArgs args = new ResponseReceivedEventArgs(); args.response = e.SocketError.ToString(); args.isError = true; OnResponseReceived(args); } }