两个蓝牙设备之间的32feet.NET连接失败 [英] 32feet.NET connection between two bluetooth device failed

查看:162
本文介绍了两个蓝牙设备之间的32feet.NET连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在蓝牙应用上使用32feet.NET。我的工作是通过蓝牙连接在两台计算机之间发送一个字符串(一台计算机是客户端,另一台是服务器)

在服务器上我写道:

Hi every one,
I'm working with 32feet.NET on my bluetooth application. I work is send a string between two computer via bluetooth connection (one computer is client, another is server)
On server I write:

Form1()
        {
            InitializeComponent();
            if ( BluetoothRadio.IsSupported )
            {
                BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
                btListener = new BluetoothListener( new Guid( "{FDA86975-9442-455D-AB86-5BB8FAEA26F3}" ) );
                btListener.ServiceName = "Ne.on Bluetooth Service";
                btListener.Authenticate = false;
                btListener.Start();

                Thread thHR = new Thread( new ThreadStart( recibiendo ) );
                thHR.Start();
            }
        }

        void recibiendo()
        {
            bool buscando = true;
            do
            {
                Console.WriteLine( "Dispositivo a la espera de conexiones entrantes..." );
                BluetoothClient client = btListener.AcceptBluetoothClient();
                Stream peerStream = client.GetStream();
                var wtr = new StreamReader( peerStream );
                var line = wtr.ReadLine();
                MessageBox.Show( line );
                while ( !wtr.EndOfStream )
                {
                    String asd = wtr.ReadLine();
                    MessageBox.Show( asd );
                }
                wtr.Close();
                btListener.Stop();
                buscando = false;
            } while ( buscando );
        }
}

On client I write:

private void Form1_Load( object sender, EventArgs e )
        {
            InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient();
            InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices();
            for ( int i = 0;i < array.Length;i++ )
            {
                this.address_array[i] = array[i].DeviceAddress;
                this.lstDevices.Items.Add( array[i].DeviceName );
            }
        }

        private void lstDevices_SelectedIndexChanged( object sender, EventArgs e )
        {
            BluetoothAddress addressSeleccionado = address_array[lstDevices.SelectedIndex];
            MessageBox.Show( address_array[lstDevices.SelectedIndex].ToString() );
            Application.DoEvents();
            var ep = new BluetoothEndPoint( addressSeleccionado, UUID );
            InTheHand.Net.Sockets.BluetoothClient cli = new InTheHand.Net.Sockets.BluetoothClient();
            cli.Connect( ep );
            System.Net.Sockets.NetworkStream peerStream = cli.GetStream();
            MessageBox.Show("Connected!");
            Application.DoEvents();
            var wtr = new StreamWriter( peerStream );
            wtr.WriteLine("Hello");
            wtr.Flush();
            MessageBox.Show("Sent message");
        }



在客户端和服务器中,UUID都是相同的:

Guid UUID = new Guid({FDA86975-9442- 455D-AB86-5BB8FAEA26F3});

我是通过TOOLS创建的 - >在Visual Studio 2012上创建Guid。



当客户端连接到服务器时,我收到一个错误:

连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机未能响应而建立连接失败。





任何机构告诉我我的代码有什么问题? bug意味着什么?以及如何解决这个问题。



谢谢等待。


In both client and server, UUID are same:
Guid UUID = new Guid("{FDA86975-9442-455D-AB86-5BB8FAEA26F3}");
I create this by TOOLS->Create Guid on Visual studio 2012.

When Client connect to server, I get an error:
"A connection attempt failed because the connected party did not properly respond after a period time, or established connection failed because connected host has failed to respond".


any body tell me what are wrong in my code? What does bug mean? and how to fix this problem.

Thanks and waiting.

推荐答案

我找到了这个解决方案,这个问题已经结束。



这个问题是我的客户的蓝牙有驱动程序问题。现在我换到另一台PC工作正常。代码没问题。

谢谢。
I found this solution, this question was closed.

This problem is my client's bluetooth has problem with driver. Now I change to another PC this working fine. No problem with code.
Thanks.


这篇关于两个蓝牙设备之间的32feet.NET连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆