public void DiscoverHugeNumberOfItems() { System.Net.Sockets.Socket dummySock = new System.Net.Sockets.Socket( System.Net.Sockets.AddressFamily.Irda, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Unspecified); IrDAClient.DiscoverDevices(Int32.MaxValue, dummySock); }
public void IrdaCliConnect() { var cli = new IrDAClient(); IrDAEndPoint epNull = null; try { var task = cli.ConnectAsync(epNull, null); Assert.Fail("expected exception"); } catch (ArgumentException) { } }
private IrDADeviceInfo SelectIrDAPeerInfo(IrDAClient client) { var devices = client.DiscoverDevices(); if (!devices.Any()) { throw new Exception("No IrDA devices found."); } return(devices[DevicePeerIndex]); }
/// <summary> /// Buscar Dispositivos. /// </summary> /// <returns>Array List con los dispositivos encontrados.</returns> public override ArrayList BuscarDispositivos() { clienteIR = new IrDAClient(); ArrayList listaDispositivos = new ArrayList(); this.informacionIR = this.clienteIR.DiscoverDevices(3); for (int i = 0; i < informacionIR.Length; i++) { listaDispositivos.Add(informacionIR[i].DeviceName); } return(listaDispositivos); }
private void SendMessage(int NumRetries, string str) { IrDAClient client = null; int CurrentTries = 0; do { try { client = new IrDAClient(ServiceName); } catch (Exception se) { if ((CurrentTries >= NumRetries)) { throw se; } } CurrentTries = CurrentTries + 1; } while (client == null & CurrentTries < NumRetries); if ((client == null)) { StatusBar1.BeginInvoke(new myDelegate(UpdateStatus), new object[] { "Error establishing contact" }); return; } System.IO.Stream stream = null; try { stream = client.GetStream(); stream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(str), 0, str.Length); StatusBar1.BeginInvoke(new myDelegate(UpdateStatus), new object[] { "Message sent!" }); txtMessagesArchive.Text = str + "\r\n" + txtMessagesArchive.Text; } catch (Exception e) { StatusBar1.BeginInvoke(new myDelegate(UpdateStatus), new object[] { "Error sending message." }); } finally { if ((!(stream == null))) { stream.Close(); } if ((!(client == null))) { client.Close(); } } }
/// <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; } }
public IrDAPort() { _client = new IrDAClient(ServiceName); try { _encoding = Encoding.GetEncoding("x-IAS"); } catch (ArgumentException) { _encoding = Encoding.ASCII; } LoadDevice(); }
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 { } }
protected override void OnLoad(EventArgs e) { try { bc = new BluetoothClient(); } catch { btnBluetooth.Enabled = false; } try { ic = new IrDAClient(); } catch { btnIr.Enabled = false; } base.OnLoad(e); }
private void bDiscover_Click(object sender, EventArgs e) { try { lbDevices.Items.Clear(); tbLog.Text = ""; IrDAClient client = new IrDAClient(); IrDADeviceInfo[] devices = client.DiscoverDevices(10); if (devices.Length == 0) { Log("No devices found"); return; } Log("Found " + devices.Length + " devices"); foreach (IrDADeviceInfo device in devices) { lbDevices.Items.Add(new DevItem(device)); } lbDevices.SelectedIndex = 0; } catch (Exception ex) { Log("There was exception while discovering devices. "); Log(" "); Log("On UNIX please check ifconfig to make sure that your IrDA "); Log("device is up. If not do ifconfig irda0 up as root. "); Log(" "); Log("On windows make sure that you compiled pnet with "); Log("--disable-cygwin, because on pure cygwin it wont work. "); Log(" "); Log("You can also try to repeat discovery. "); Log(" "); Log("Exception dump: "); Log(ex.ToString()); } }
private void SendMessage(int NumRetries, string str) { IrDAClient client = null; int CurrentTries = 0; //---try to establish a connection--- do { try { client = new IrDAClient(ServiceName); } catch (Exception se) { if ((CurrentTries >= NumRetries)) { throw se; } } CurrentTries = CurrentTries + 1; } while (client == null & CurrentTries < NumRetries); //---timeout occurred--- if ((client == null)) { txtMessagesArchive.BeginInvoke(new myDelegate(UpdateStatus), new object[] { "Error establishing contact" }); return; } //---send the message over a stream object--- System.IO.Stream stream = null; try { stream = client.GetStream(); stream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(str), 0, str.Length); //---update the status bar--- txtMessagesArchive.BeginInvoke(new myDelegate(UpdateStatus), new object[] { "Message sent!" }); //---display the message that was sent--- txtMessagesArchive.Text = str + Environment.NewLine + txtMessagesArchive.Text; } catch (Exception e) { txtMessagesArchive.BeginInvoke(new myDelegate(UpdateStatus), new object[] { "Error sending message." }); } finally { if ((!(stream == null))) { stream.Close(); } if ((!(client == null))) { client.Close(); } } }
private ObexStatusCode Connect() { if (!connected) { if (ns == null) { try { if (uri.Host.Length == 0) { System.Diagnostics.Debug.Assert(m_alreadyConnectedObexStream != null); System.Diagnostics.Debug.Assert(m_alreadyConnectedObexStream.CanRead && m_alreadyConnectedObexStream.CanWrite); ns = m_alreadyConnectedObexStream; } else { if (IrDAAddress.TryParse(uri.Host, out var address)) { IrDAClient client = new IrDAClient(); string serviceName; switch (uri.Scheme) { //potential for other obex based profiles to be added default: serviceName = IrDAService.ObjectExchange; break; } client.Connect(new IrDAEndPoint(address, serviceName)); if (!client.Connected) { return(ObexStatusCode.NotFound); } ns = client.GetStream(); } else if (BluetoothAddress.TryParse(uri.Host, out BluetoothAddress ba)) { BluetoothClient cli = new BluetoothClient(); Guid serviceGuid; switch (uri.Scheme) { case SchemeNames.Ftp: serviceGuid = BluetoothService.ObexFileTransfer; break; //potential for other obex based profiles to be added case SchemeNames.Sync: serviceGuid = BluetoothService.IrMCSyncCommand; break; case SchemeNames.Pbap: serviceGuid = BluetoothService.PhonebookAccessPse; break; case SchemeNames.Map: serviceGuid = BluetoothService.MessageAccessProfile; break; default: serviceGuid = BluetoothService.ObexObjectPush; break; } cli.Connect(ba, serviceGuid); if (!cli.Connected) { return(ObexStatusCode.NotFound); } ns = cli.GetStream(); } else { //assume a tcp host s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipa = null; var addresses = System.Net.Dns.GetHostAddresses(uri.Host); if (addresses.Length > 0) { ipa = addresses[0]; } else { throw new WebException("Host not recognised", WebExceptionStatus.NameResolutionFailure); } IPEndPoint ipep = new IPEndPoint(ipa, 650); s.Connect(ipep); } if (ns == null) // BluetoothClient used above { ns = new System.Net.Sockets.NetworkStream(s, true); } // Timeout //ns.ReadTimeout = timeout; //ns.WriteTimeout = timeout; } return(Connect_Obex()); } finally { if (s != null && !s.Connected) { s = null; } } } } Debug.Fail("Don't know that we every get here (Connect when connected)."); return((ObexStatusCode)0); }
public static IrDADeviceInfo[] DoParseDeviceList(byte[] buffer) { return(IrDAClient.ParseDeviceList(buffer)); }
public void DiscoverNullSocket() { IrDAClient.DiscoverDevices(4, null); }