//[Test] public void IrdaLsnrAccept2_None() { // No usage exceptions var lsnr = new IrDAListener("unit-test"); var task = lsnr.AcceptIrDAClientAsync(null); var task2 = lsnr.AcceptSocketAsync(null); }
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); }
/// <summary> /// Da comienzo a un servicio de comunicaciones como Servidor. /// </summary> public override void Servir() { try { Cursor.Current = Cursors.WaitCursor; clienteIR = new IrDAClient(); extremoIR = new IrDAEndPoint(informacionIR[seleccionado].DeviceID, "Dame una Vida"); escuchaIR = new IrDAListener(extremoIR); escuchaIR.Start(); clienteIR = escuchaIR.AcceptIrDAClient(); Cursor.Current = Cursors.Default; this.nombreRemoto = clienteIR.RemoteMachineName; if (OnAlguienConectado != null) { OnAlguienConectado(this, new EventArgs()); } } catch { } }
/// <summary> /// Initializes a new instance of the ObexListener class specifiying the transport to use. /// </summary> public ObexListener(ObexTransport transport) { #if WinCE PlatformVerification.ThrowException(); #endif switch(transport) { case ObexTransport.Bluetooth: ServiceRecord record = CreateServiceRecord(); bListener = new BluetoothListener(BluetoothService.ObexObjectPush, record); bListener.ServiceClass = ServiceClass.ObjectTransfer; break; case ObexTransport.IrDA: iListener = new IrDAListener("OBEX"); break; case ObexTransport.Tcp: tListener = new TcpListener(IPAddress.Any, 650); break; default: throw new ArgumentException("Invalid transport specified"); } this.transport = transport; }