Ejemplo n.º 1
0
        /// <summary>
        /// Compares two <see cref="IrDAEndPoint"/> instances for equality.
        /// </summary>
        /// -
        /// <param name="obj">The <see cref="BluetoothEndPoint"/>
        /// to compare with the current instance.
        /// </param>
        /// -
        /// <returns><c>true</c> if <paramref name="obj"/>
        /// is a <see cref="IrDAEndPoint"/> and equal to the current instance;
        /// otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            IrDAEndPoint irep = obj as IrDAEndPoint;

            if (irep != null)
            {
                return(this.Address.Equals(irep.Address) && this.ServiceName.Equals(irep.ServiceName));
            }

            return(base.Equals(obj));
        }
Ejemplo n.º 2
0
        private ObexStatusCode Connect()
        {
            if (!connected)
            {
                if (ns == null)
                {
                    try {
#if NETCF
                        // Will be set to false in some Bluetooth cases (e.g. Widcomm and Bluetopia)...
                        bool isWinCeSockets = true;
#endif
                        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
                        {
                            BluetoothAddress ba;
                            IrDAAddress      ia;
                            if (BluetoothAddress.TryParse(uri.Host, out ba))
                            {
                                // No good on Widcomm! s = new Socket(AddressFamily32.Bluetooth, SocketType.Stream, BluetoothProtocolType.RFComm);
                                BluetoothClient cli;
                                if (_btFactory == null)
                                {
                                    cli = new BluetoothClient();
                                }
                                else
                                {
                                    cli = _btFactory.CreateBluetoothClient();
                                }
                                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;

                                default:
                                    serviceGuid = BluetoothService.ObexObjectPush;
                                    break;
                                }


                                BluetoothEndPoint bep = new BluetoothEndPoint(ba, serviceGuid);
                                cli.Connect(bep);
                                ns = cli.GetStream();
#if NETCF
                                try {
                                    Socket tmp = cli.Client; // Attempt to get the Socket
                                    Debug.Assert(isWinCeSockets);
                                } catch (NotSupportedException) {
                                    isWinCeSockets = false;
                                }
#endif
                            }
                            else if (IrDAAddress.TryParse(uri.Host, out ia))
                            {
                                //irda
                                s = new Socket(AddressFamily.Irda, SocketType.Stream, ProtocolType.IP);

                                IrDAEndPoint iep = new IrDAEndPoint(ia, "OBEX");

                                s.Connect(iep);
                            }
                            else
                            {
                                //assume a tcp host
                                s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                                IPAddress ipa;
                                try {
                                    ipa = IPAddress.Parse(uri.Host);
                                } catch {
                                    // Compile-time: warning CS0618: 'System.Net.Dns.Resolve(string)'
                                    //    is obsolete: 'Resolve is obsoleted for this type,
                                    //    please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202'
                                    // However GetHostEntry isn't supported on NETCFv1,
                                    // so just keep it and disable the warning on
                                    // the other platforms.
#if V1
/*
 #endif
 #pragma warning disable 618
 #if V1
 */
#endif
                                    ipa = System.Net.Dns.Resolve(uri.Host).AddressList[0];
#if V1
/*
 #endif
 #pragma warning restore 618
 #if V1
 */
#endif
                                }

                                IPEndPoint ipep = new IPEndPoint(ipa, 650);

                                s.Connect(ipep);
                            }

                            if (ns == null) // BluetoothClient used above
                            {
                                ns = new NetworkStream(s, true);
                            }

#if NETCF
                            if (isWinCeSockets)
                            {
                                // Winsock on WinCE does _not_ support timeouts!
                                ns = new InTheHand.Net.Bluetooth.Factory.TimeoutDecorStream(ns);
                            }
#endif
                            // 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);
        }