Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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");
        }

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.
Posted
Updated 2-Sep-13 20:25pm
v3
Comments
Member 10676658 15-Aug-14 5:50am    
hi
i wanted to give command to my laptop using mobile bluetooth please help me

1 solution

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.
 
Share this answer
 
v2
Comments
Sushil Mate 3-Sep-13 2:25am    
would you like to tell us your solution here?
idenizeni 3-Sep-13 2:46am    
If you are going to mark your post as a solution you should at least post the solution you found.
Tuyển Đỗ 3-Sep-13 5:28am    
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.
idenizeni 3-Sep-13 13:42pm    
Thanks for the update.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900