Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Mon Apr 27, 2009 7:00 pm

Seems like I remembered incorrectly, there is no ConnectService in the ObexFTPClient.

It's really simple though:
You need to know the service channel number for the RemoteService. then first connect to the RemoteDevice like it shows in the ObexFTPClient and then just call remotedevice.Connect(<servicechannelnumber>, "Name of service");

Regards,
Jonas

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 12:01 am

Originally posted by Jonas

Seems like I remembered incorrectly, there is no ConnectService in the ObexFTPClient.

It's really simple though:
You need to know the service channel number for the RemoteService. then first connect to the RemoteDevice like it shows in the ObexFTPClient and then just call remotedevice.Connect(<servicechannelnumber>, "Name of service");

Regards,
Jonas

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 12:05 am

Originally posted by Jonas

Seems like I remembered incorrectly, there is no ConnectService in the ObexFTPClient.

It's really simple though:
You need to know the service channel number for the RemoteService. then first connect to the RemoteDevice like it shows in the ObexFTPClient and then just call remotedevice.Connect(<servicechannelnumber>, "Name of service");

Regards,
Jonas



maybe it is stupid question, but what are examples od "name of service" oraz <servicechannelnumber> ??:)

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 1:13 am

another question. It isn't the same thing. When I use that m_serviceCurrent2 = device.ConnectService(1, name);

it works good but when i want to send a file in my phone there are not "if you want to receive file click yes", but there are sth about password etc:(

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Tue Apr 28, 2009 3:31 am

Yes, file transfers requires bonding. Google bluetooth bonding.

Regards,
Jonas

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 3:42 am

Originally posted by Jonas

Yes, file transfers requires bonding. Google bluetooth bonding.

Regards,
Jonas


i dont understand this. When I use service discover it discover service and send file just ask if you wont to receive file from .... .
now when i manually write service it requires bonding? is there any possibility to not discover service and work as if there are discover srvice?

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Tue Apr 28, 2009 10:54 am

I don't understand what you are saying. Bonding is required once, to determine that you allow connections between the two devices.
If you have managed to send files before the password is something else that I am not aware of.

Regards,
Jonas

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 12:02 pm

Originally posted by Jonas

I don't understand what you are saying. Bonding is required once, to determine that you allow connections between the two devices.
If you have managed to send files before the password is something else that I am not aware of.

Regards,
Jonas



I'm saying that effect isn't the same with discover services and without it. Desirable effect is as service discovery.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Tue Apr 28, 2009 12:23 pm

Then I have no idea, there is no difference in how BlueTools connects between the two.

Regards,
Jonas

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 12:34 pm

Originally posted by Jonas

Then I have no idea, there is no difference in how BlueTools connects between the two.

Regards,
Jonas


there is differance:

1. with doscovery services. When it start "push" in device you will only see "if you want to receive a file please click yes" oor someting like that, here you got the code:

private void selectedDevice_ServiceDiscoveryCompleted(object sender, BlueToolsEventArgs eventArgs)
{
// when service discovery is complete - let us re-enable the discover button.
// It is okay to try to update the device list
discoverBtn.Enabled = true;

// re-enable the device list
deviceList.Enabled = true;

// set error event handler for the device
RemoteDevice device = (RemoteDevice)sender;
device.Error += new BlueToolsEventHandler(device_Error);

// get all services found
Service[] services = (Service[])((DiscoveryEventArgs)eventArgs).Discovery;

// if we have a service since before, close the stream
if (m_streamCurrent != null)
{
m_streamCurrent.Close();
m_streamCurrent = null;
}

// and remove the service
if (m_serviceCurrent != null)
{
m_serviceCurrent = null;
}

// if we found a new service...
if (services.Length > 0)
{
// ...get OPP service object
m_serviceCurrent = (RemoteService)services[0];

try
{
// create an ObexObjectPush object connected to the ServiceStream
m_objectPush = new ObexObjectPush(3); // wait forever

// marshal event to this class thread
m_objectPush.Parent = this;

// setup event handlers
m_objectPush.Error += new ObexEventHandler(m_objectPush_Error);
m_objectPush.PutFileBegin += new ObexEventHandler(m_objectPush_PutFileBegin);
m_objectPush.PutFileProgress += new ObexEventHandler(m_objectPush_PutFileProgress);
m_objectPush.PutFileEnd += new ObexEventHandler(m_objectPush_PutFileEnd);
m_objectPush.DisconnectEnd += new ObexEventHandler(m_objectPush_DisconnectEnd);

// enable the Push button
// sendBtn.Enabled = true;

// inform the user what to do next
informLabel.Text = "Click on Send to select file(s) to push to device.";
MessageBox.Show("good1");

}
catch (Exception exc)
{
// sendBtn.Enabled = false;

MessageBox.Show(exc.Message);
}
}
MessageBox.Show("1 no");
}




2. In this case, without searching for services, when you "push", in device you will see "if you want to add device.....(here is name of my computer's bluetootha) click yes" then it's nneccessary to write password so it's totally different from 1. here is code:


private void selectedDevice_ServiceDiscoveryCompleted2(object sender, BlueToolsEventArgs eventArgs)
{
// when service discovery is complete - let us re-enable the discover button.
// It is okay to try to update the device list
discoverBtn.Enabled = true;

// re-enable the device list
deviceList.Enabled = true;

// set error event handler for the device
RemoteDevice device = (RemoteDevice)sender;
device.Error += new BlueToolsEventHandler(device_Error1);

// get all services found
// Service[] services = (Service[])((DiscoveryEventArgs)eventArgs).Discovery;

// if we have a service since before, close the stream
if (m_streamCurrent != null)
{
m_streamCurrent.Close();
m_streamCurrent = null;
}

// and remove the service
if (m_serviceCurrent != null)
{
m_serviceCurrent = null;
}

// if we found a new service...



// if (services.Length > 0)
// {
// ...get OPP service object
string name = "OOP";
m_serviceCurrent = device.ConnectService(6, name);


try
{
// create an ObexObjectPush object connected to the ServiceStream
m_objectPush = new ObexObjectPush(-1); // wait forever

// marshal event to this class thread
m_objectPush.Parent = this;

// setup event handlers
m_objectPush.Error += new ObexEventHandler(m_objectPush_Error);
m_objectPush.PutFileBegin += new ObexEventHandler(m_objectPush_PutFileBegin);
m_objectPush.PutFileProgress += new ObexEventHandler(m_objectPush_PutFileProgress);
m_objectPush.PutFileEnd += new ObexEventHandler(m_objectPush_PutFileEnd);
m_objectPush.DisconnectEnd += new ObexEventHandler(m_objectPush_DisconnectEnd);

// enable the Push button
sendBtn.Enabled = true;

// inform the user what to do next
informLabel.Text = "Click on Send to select file(s) to push to device.";
MessageBox.Show("good3");

}
catch (Exception exc)
{
// sendBtn.Enabled = false;

MessageBox.Show(exc.Message);
}
// }
MessageBox.Show("3 no");
}

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Tue Apr 28, 2009 12:41 pm

I meant that there are no difference inside BlueTools.
Maybe you are not connecting to the same service?

Other than that, I can't help you anymore.

Regards,
Jonas

poland
Posts: 24
Joined: Thu Apr 02, 2009 6:22 pm

RE: how to abort service discovery?

Tue Apr 28, 2009 9:11 pm

ok so let's get back to the main problem. Is there any possibility to short time of discover services? Becouse abort thread doesnt work. Sometimes it takes 1 minute to discover this services. What to do that? If I buy stronger bluotooth antenna it will help?

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Wed Apr 29, 2009 11:22 am

There are really only two reasons why a service discovery would take a long time on a remote device:

* You are making too many calls at once, running several discoveries and connections at once is not recommended.
* The general area is flooded with bluetooth signals. If you are running this test in an environment with a lot of devices your device is bombarded with requests and "pings" from other devices.

If the first, only run your service discovery and don't do lots of other things.
If the latter, move out of the crowded bluetooth area.


Regards,
Jonas

scippy
Posts: 33
Joined: Sat Feb 04, 2006 4:37 pm
Location: Italy
Contact: Website

RE: how to abort service discovery?

Mon May 11, 2009 2:38 pm

So I can't use in a discotheque? I have very long time for network.DiscoverDevicesAsync. Before it is completed sometimes we also need 5 minutes.
Any suggestion!? I can't move out of the crowded bluetooth area if I want send message inside a disco!
Thanks

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: how to abort service discovery?

Mon May 11, 2009 3:05 pm

How to you send this message? Bluetooth technology isn't meant to be used to send general broadcasts like you suggest. One major problem that you'll encounter soon enough is that you aren't allowed to connect to a remote device without first bonding with the device.

Regards,
Jonas

Return to “BlueTools”