I'm writing a simple bluetooth application for sending a data from my Samsung Omnia 2 to my laptop. I'm experimenting first by sending a simple Hello message but am getting this error.
Socket Exception
No connection could be made because the target computer actively refused it.
I know its a relatively common issue so can someone here who's experience help me with it? I am shamefully a beginner to programming so I don't thing I can solve this on my own.
My code. Which you will notice is mostly butchered from the original sample code.
Samsung Omnia 2 Side : Supposedly searches for the device when I click the button, then sends a single hello to the stream.
private void btnConnect_Click(object sender, EventArgs e)
{
{
SelectBluetoothDeviceDialog dlg = new SelectBluetoothDeviceDialog();
DialogResult result = dlg.ShowDialog();
if (result != DialogResult.OK)
{
return;
}
BluetoothDeviceInfo device = dlg.SelectedDevice;
BluetoothAddress addr = device.DeviceAddress;
BluetoothEndPoint ep = new BluetoothEndPoint(addr, ServiceName);
BluetoothClient cli = new BluetoothClient();
cli.Connect(ep);
Stream peerStream = cli.GetStream();
byte[ buffer = new byte[255];
buffer = System.Text.ASCIIEncoding.ASCII.GetBytes("Hello");
peerStream.Write(buffer, 0, buffer.Length);
}
Laptop side. Just waits to receive the message.
private void timer1_Tick(object sender, EventArgs e)
{
int bytesRead;
BluetoothClient client = null;
BluetoothListener lis = new BluetoothListener(ServiceName);
lis.Start();
string text;
Stream peerstream = null;
byte[ Buffer = null;
try
{
client = lis.AcceptBluetoothClient();
// blocking call
peerstream = client.GetStream();
bytesRead = peerstream.Read(Buffer, 0, 100);
textBox1.Text = System.Text.ASCIIEncoding.ASCII.GetString(Buffer,0,bytesRead);
}
catch (Exception)
{
MessageBox.Show("Error listening to incoming message");
}
}
I'm using
Guid ServiceName = new Guid("{00112233-4455-6677-8899-aabbccddeeff}"); as my ID by the way.