/// <summary> /// Detiene la conexión. /// </summary> public override void Parar() { if (clienteIR != null) { clienteIR.Close(); clienteIR = null; if (escuchaIR != null) { escuchaIR.Stop(); } Cursor.Current = Cursors.Default; } }
private string ReceiveMessage() { int bytesRead = 0; IrDAListener listener = new IrDAListener(ServiceName); IrDAClient client = null; System.IO.Stream stream = null; byte[] Buffer = new byte[MAX_MESSAGE_SIZE - 1]; string str = string.Empty; try { listener.Start(); //---blocking call--- client = listener.AcceptIrDAClient(); stream = client.GetStream(); bytesRead = stream.Read(Buffer, 0, Buffer.Length); //---format the received message--- str = ">" + System.Text.ASCIIEncoding.ASCII.GetString(Buffer, 0, bytesRead); } catch (SocketException ex) { //---ignore error--- } catch (Exception e) { txtMessagesArchive.BeginInvoke(new myDelegate(UpdateStatus), new object[] { e.ToString() }); } finally { if ((!(stream == null))) { stream.Close(); } if ((!(client == null))) { client.Close(); } listener.Stop(); } return(str); }