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");
}
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.