I'm not very sure but for some reasons I can't use a BlueToothListener that receives string information.
I tried following this example, and it doesn't seems to work.
Code Snippet
private Guid Rffcomm = BluetoothService.RFCommProtocol;
private void btnConnect_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
{
try
{
BluetoothClient btSender = null;
btSender = new BluetoothClient();
btSender.Connect(new BluetoothEndPoint(selectedAddr, Rffcomm));
MessageBox.Show("1");
StreamWriter swSender = new StreamWriter(btSender.GetStream());
swSender.WriteLine("Test 1");
//swSender.Flush();
// swSender.Close(); // At first it worked, but after some tries, IOsocket exception keeps popping out.
}
catch (Exception se)
{
MessageBox.Show(se.Message);
}
}
}
void listening()
{
try
{
bool run = true;
BluetoothListener btl = new BluetoothListener(Rffcomm);
btl.Start();
while(run)
{
BluetoothClient btReceiver = btl.AcceptBluetoothClient();
StreamReader srReceiver = new StreamReader(btReceiver.GetStream());
String writeInfo = srReceiver.ReadLine();
test = writeInfo;
srReceiver.Close();
}
MessageBox.Show(test);
}
catch(Exception ex) { MessageBox.Show(ex.Message); }
}
private void button1_Click(object sender, EventArgs e)
{
// Start a new thread to deal with an incoming Bluetooth connection
Thread t = new Thread(new ThreadStart(listening));
t.Start();
}