 |
|
<<O>> Difference Topic
HowTo05
(10 - 17 Sep 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | | | | |
> > | In Marge, the concept of server-client is used and the server starts a connection (registering a service) that clients would be able to connect. A server or a client can perform inquiries, but usually clients will do it to get the connection string. | | | 1. Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages) |
|
<<O>> Difference Topic
HowTo05
(9 - 10 Jun 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | | | Also, take a look in the demo applications, including:
| |
> > | | | | 1. Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages) |
|
<<O>> Difference Topic
HowTo05
(8 - 24 Apr 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | | | Before start, be sure you have read how to use Marge in Eclipse IDE and Netbeans 6 IDE (by Eivar Montenegro Mosquera). | |
> > | Also, take a look in the demo applications, including:
| | | 1. Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages) |
|
<<O>> Difference Topic
HowTo05
(7 - 22 Apr 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | | | //Creates a server. The service UUID will be generated by the name.
//The serverDevice will be returned by ConnectionListenerImpl?. | |
< < | AutoConnect?.createServer("MargeBluechatServer", | > > | AutoConnect?.createClient("MargeBluechatServer", | | | new CommunicationListenerImpl?(), new ConnectionListenerImpl?());
|
|
<<O>> Difference Topic
HowTo05
(6 - 03 Apr 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | | | Basically you create a protocol factory, create a configuration for the server and send this configuration to the factory. Your server device will return by a listener. If you do not specify nothing, default stuff will be used, such as for example, a default service. | |
< < | // Creating a factory using RFCOMM protocol if you want to use L2CAP? protocol instead,
//try L2CAPCommunicationFactory? | > > | // Creating a factory using RFCOMM protocol if you want to use L2CAP? protocol
//instead, try L2CAPCommunicationFactory? | | | CommunicationFactory? factory = new RFCOMMCommunicationFactory?(); | |
< < | // Creating a server configuration. You can set specific configurations using this class. | > > | // Creating a server configuration. You can set specific configurations using
//this class. | | | ServerConfiguration? sconf = new ServerConfiguration?(new CommunicationListenerImpl?()); | |
< < | // Creating a server with the factory. The server device instance will be rertuned by the ConnectionListenerImpl?, | > > | // Creating a server with the factory. The server device instance will be
//rertuned by the ConnectionListenerImpl?, | | | //which is a implementation of ConnectionListener?.
factory.waitClients(sconf, new ConnectionListenerImpl?()); | |
> > | | | | | | | The devices found in the inquiry process will be returned by InquiryListenerImpl, which is a implementation of InquiryListener | |
> > | | | | // Starting GIAC inquiry for devices. You can do LIAC inquiries changing the method | |
< < | DeviceDiscoverer?.getInstance().startInquiryGIAC(new InquiryListenerImpl?()); | > > | DeviceDiscoverer?.getInstance().startInquiryGIAC(
new InquiryListenerImpl?()); | | | //Cancel inquiry
DeviceDiscoverer?.getInstance().cancelInquiry(); | | | The devices found in the inquiry process will be returned by ServiceSearchListenerImpl which is a implementation of ServiceSearchListener. If you have not specified a specific UUID service, the default will be used, otherwise you can send as a parameter in this startSearch methods. | |
> > | | | | // Starting search for services in a found device | |
< < | ServiceDiscoverer?.getInstance().startSearch(remoteDeviceFound, new ServiceSearchListenerImpl?()); | > > | ServiceDiscoverer?.getInstance().startSearch(remoteDeviceFound,
new ServiceSearchListenerImpl?()); | | |
Connect a client | |
< < | //Creates a client configuration using the specific ServiceRecord? found by ServiceSearcher?
ClientConfiguration? clientConfig = new ClientConfiguration?(serviceRecord, new CommunicationListenerImpl?()); | > > | //Creates a client configuration using the specific ServiceRecord? found
//by ServiceSearcher?
ClientConfiguration? clientConfig = new ClientConfiguration?(serviceRecord,
new CommunicationListenerImpl?()); | | | //Create a protocol factory to get the client
CommunicationFactory? factory = new RFCOMMCommunicationFactory?(); | | | 2. AutoConnect | |
< < | If you do not want to program the inquiry process, you can use AutoConnect. Be sure the place that the application will run does not contain much Bluetooth devices and is running that the service that you want, otherwise AutoConnect can take a long time to response back or can connect in another device with the same service running. It is very cool, but it does not work in some devices, because of its implementation problems. | > > | If you do not want to program the inquiry and search process, you can use AutoConnect. Be sure the place that the application will run does not contain too much Bluetooth devices and is running the service you want to connect, otherwise AutoConnect can take a long time to response back or possible will connect in another device with the same service running. It is a very cool feature, but it does not work in some devices, because of some implementation problems. Take a try! It is easy and fun! | | | Create a server | | | Create a server | |
> > | | | | //Creates a server. The service UUID will be generated by the name.
//The serverDevice will be returned by ConnectionListenerImpl?. | |
< < | AutoConnect?.createServer("MargeBluechatServer", new CommunicationListenerImpl?(), new ConnectionListenerImpl?()); | > > | AutoConnect?.createServer("MargeBluechatServer",
new CommunicationListenerImpl?(), new ConnectionListenerImpl?()); | | |
Client connects to a server | | | Client connects to a server | |
> > | | | | //Creates a server. The service UUID will be generated by the name. | |
< < | ClientDevice? device = AutoConnect?.createServer("MargeBluechatServer", new CommunicationListenerImpl?()); | > > | ClientDevice? device = AutoConnect?.createServer("MargeBluechatServer",
new CommunicationListenerImpl?()); | | |
Check "Building a Java ME Bluetooth chat in 12 minutes..." with Marge AutoConnect? in this post. | | | //send a message yo a specific address
unicastLayer.sendMessage(stringAddress, "Marge rocks!".getBytes()); | |
< < | //all the names on the server will be returned by receiveNameOnServer(String address, String name) method | > > | //all the names on the server will be returned by
//receiveNameOnServer(String address, String name) method | | | unicastLayer.getNamesOnServer();
//you need to implement it |
|
<<O>> Difference Topic
HowTo05
(5 - 03 Apr 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | | | ClientDevice? device = AutoConnect?.createServer("MargeBluechatServer", new CommunicationListenerImpl?());
| |
> > | Check "Building a Java ME Bluetooth chat in 12 minutes..." with Marge AutoConnect? in this post. | | | 3. Layer
If you want special behavior in the messages exchanged, you can use the new concept of layer. It is still evolving to maybe something like a decorator. Currently, there is a unicast layer, if you want your device having this behavior, just extend UnicastMessageLayer. After that, you can instantiate it passing a device and then use its methods to have the special behavior. |
|
<<O>> Difference Topic
HowTo05
(4 - 29 Mar 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | |
< < | Marge 0.5 is almost compatible with 0.4.0. Try to add the new jar and check what have changed, it is intuitive. Currently, there is two ways to have devices connected using Marge: Default and AutoConnect. In addition, you can use Marge independently, like if you just want the inquiry stuff, for example. | > > | Marge 0.5 is almost compatible with 0.4.0. Try to add the new jar and check what have changed, it is intuitive. Currently, there is two ways to have devices connected using Marge: Default (1) and AutoConnect (2). In addition, you can use Marge independently, like if you just want the inquiry stuff, for example. | | | Before start, be sure you have read how to use Marge in Eclipse IDE and Netbeans 6 IDE (by Eivar Montenegro Mosquera). | |
< < | Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages) | > > | 1. Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages) | | |
Basically you need to start a server and the client needs to inquiry for the Bluetooth devices, search for specific service in a device and then connect. After this process, the both can exchange messages. | | | device.close();
| |
< < | AutoConnect | > > | 2. AutoConnect | | | If you do not want to program the inquiry process, you can use AutoConnect. Be sure the place that the application will run does not contain much Bluetooth devices and is running that the service that you want, otherwise AutoConnect can take a long time to response back or can connect in another device with the same service running. It is very cool, but it does not work in some devices, because of its implementation problems. | | | ClientDevice? device = AutoConnect?.createServer("MargeBluechatServer", new CommunicationListenerImpl?());
| |
< < | Layer | > > | 3. Layer | | | If you want special behavior in the messages exchanged, you can use the new concept of layer. It is still evolving to maybe something like a decorator. Currently, there is a unicast layer, if you want your device having this behavior, just extend UnicastMessageLayer. After that, you can instantiate it passing a device and then use its methods to have the special behavior. |
|
<<O>> Difference Topic
HowTo05
(3 - 29 Mar 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | |
< < | Marge 0.5 is almost compatible with 0.4.0. Try to add the new jar and check what have changed, it is intuitive. Currently, there is two ways to have devices connected using Marge: Default and AutoConnect?. In adittion, you can use Marge independently, like if you just want the inquirier stuff, for example. | > > | Marge 0.5 is almost compatible with 0.4.0. Try to add the new jar and check what have changed, it is intuitive. Currently, there is two ways to have devices connected using Marge: Default and AutoConnect. In addition, you can use Marge independently, like if you just want the inquiry stuff, for example. | | | Before start, be sure you have read how to use Marge in Eclipse IDE and Netbeans 6 IDE (by Eivar Montenegro Mosquera). | | | Basically you need to start a server and the client needs to inquiry for the Bluetooth devices, search for specific service in a device and then connect. After this process, the both can exchange messages. | |
< < | Start a Server, communicating with the server | > > | Interfaces that will have to be implemented
Before we start, Marge uses some interfaces that will be listeners in the inquiry process, message received, etc. We are going to explain each one, because they will be used in the next steps.
- CommunicationListener - It is used by both server and client device to notify received message and possible errors in receiving them.
- ConnectionListener - When a connection is established and because the server waits asynchronous, the server will be notified and returned by this interface.
- InquiryListener - The interface that returns the devices found. Used by DeviceInquirier.
- ServiceSearchListener - The interface that returns the services found. Used by ServiceSearcher.
Start a Server | | |
Basically you create a protocol factory, create a configuration for the server and send this configuration to the factory. Your server device will return by a listener. If you do not specify nothing, default stuff will be used, such as for example, a default service. | | | Inquiry for Devices | |
< < | The devices found in the inquiry process will be returned by InquiryListenerImpl?, which is a implementation of InquiryListener? | > > | The devices found in the inquiry process will be returned by InquiryListenerImpl, which is a implementation of InquiryListener | | |
// Starting GIAC inquiry for devices. You can do LIAC inquiries changing the method | | | Search for Services | |
< < | The devices found in the inquiry process will be returned by ServiceSearchListenerImpl? which is a implementation of ServiceSearchListener?. If you have not specified a specific UUID service, the default will be used, otherwise you can send as a parameter in this startSearch methods. | > > | The devices found in the inquiry process will be returned by ServiceSearchListenerImpl which is a implementation of ServiceSearchListener. If you have not specified a specific UUID service, the default will be used, otherwise you can send as a parameter in this startSearch methods. | | |
// Starting search for services in a found device
ServiceDiscoverer.getInstance().startSearch(remoteDeviceFound, new ServiceSearchListenerImpl());
| |
< < | Connect and start | > > | Connect a client | | |
//Creates a client configuration using the specific ServiceRecord found by ServiceSearcher | | | device.close();
| |
> > | AutoConnect | | | | |
< < | AutoConnect?
If you do not want to program the inquiry process, you can use AutoConnect?. Be sure the place that the application will run does not contain much Bluetooth devices and is running that the service that you want, otherwise AutoConnect? can take a long time to response back or can connect in another same service. | > > | If you do not want to program the inquiry process, you can use AutoConnect. Be sure the place that the application will run does not contain much Bluetooth devices and is running that the service that you want, otherwise AutoConnect can take a long time to response back or can connect in another device with the same service running. It is very cool, but it does not work in some devices, because of its implementation problems. | | | Create a server | | | Layer | |
< < | If you want special behavior in the messages exchanged, you can use the new concept of layer. It is still evolving to maybe something like a decorator. Currently, there is a unicast layer, if you want your device having this behavior, just extend UnicastMessageLayer?. After that, you can instantiate it passing a device and then use its methods to have the special behavior. | > > | If you want special behavior in the messages exchanged, you can use the new concept of layer. It is still evolving to maybe something like a decorator. Currently, there is a unicast layer, if you want your device having this behavior, just extend UnicastMessageLayer. After that, you can instantiate it passing a device and then use its methods to have the special behavior. | | |
//send a message yo a specific address |
|
<<O>> Difference Topic
HowTo05
(2 - 17 Mar 2008 - Main.brunogh)
|
| |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5 | |
< < | Marge 0.5 is almost compatible with 0.4.0. Try o add the new jar and check what have changed, Currently there is two ways to have devices connected using Marge: Default and AutoConnect?. | > > | Marge 0.5 is almost compatible with 0.4.0. Try to add the new jar and check what have changed, it is intuitive. Currently, there is two ways to have devices connected using Marge: Default and AutoConnect?. In adittion, you can use Marge independently, like if you just want the inquirier stuff, for example. | | | | |
> > | Before start, be sure you have read how to use Marge in Eclipse IDE and Netbeans 6 IDE (by Eivar Montenegro Mosquera). | | | Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages) | | |
//Creates a client configuration using the specific ServiceRecord found by ServiceSearcher | |
< < | ClientConfiguration? clientConfig = new ClientConfiguration?(serviceRecord, CommunicationListenerImpl?); | > > | ClientConfiguration? clientConfig = new ClientConfiguration?(serviceRecord, new CommunicationListenerImpl?()); | | | //Create a protocol factory to get the client
CommunicationFactory? factory = new RFCOMMCommunicationFactory?(); | | |
//Creates a server. The service UUID will be generated by the name.
//The serverDevice will be returned by ConnectionListenerImpl. | |
< < | AutoConnect?.createServer("MargeBluechatServer", communicationListenerImpl, connectionListenerImpl); | > > | AutoConnect?.createServer("MargeBluechatServer", new CommunicationListenerImpl?(), new ConnectionListenerImpl?()); | | |
Client connects to a server
//Creates a server. The service UUID will be generated by the name. | |
< < | ClientDevice? device = AutoConnect?.createServer("MargeBluechatServer", communicationListenerImpl); | > > | ClientDevice? device = AutoConnect?.createServer("MargeBluechatServer", new CommunicationListenerImpl?()); | | |
Layer |
|
<<O>> Difference Topic
HowTo05
(1 - 15 Mar 2008 - Main.brunogh)
|
|
> > |
| META TOPICPARENT | name="Version05" |
How to Start with Marge 0.5
Marge 0.5 is almost compatible with 0.4.0. Try o add the new jar and check what have changed, Currently there is two ways to have devices connected using Marge: Default and AutoConnect?.
Default (Inquiry for Devices -> Search for Services -> Connect and start exchanging messages)
Basically you need to start a server and the client needs to inquiry for the Bluetooth devices, search for specific service in a device and then connect. After this process, the both can exchange messages.
Start a Server, communicating with the server
Basically you create a protocol factory, create a configuration for the server and send this configuration to the factory. Your server device will return by a listener. If you do not specify nothing, default stuff will be used, such as for example, a default service.
// Creating a factory using RFCOMM protocol if you want to use L2CAP protocol instead,
//try L2CAPCommunicationFactory
CommunicationFactory factory = new RFCOMMCommunicationFactory();
// Creating a server configuration. You can set specific configurations using this class.
ServerConfiguration sconf = new ServerConfiguration(new CommunicationListenerImpl());
// Creating a server with the factory. The server device instance will be rertuned by the ConnectionListenerImpl,
//which is a implementation of ConnectionListener.
factory.waitClients(sconf, new ConnectionListenerImpl());
Inquiry for Devices
The devices found in the inquiry process will be returned by InquiryListenerImpl?, which is a implementation of InquiryListener?
// Starting GIAC inquiry for devices. You can do LIAC inquiries changing the method
DeviceDiscoverer.getInstance().startInquiryGIAC(new InquiryListenerImpl());
//Cancel inquiry
DeviceDiscoverer.getInstance().cancelInquiry();
Search for Services
The devices found in the inquiry process will be returned by ServiceSearchListenerImpl? which is a implementation of ServiceSearchListener?. If you have not specified a specific UUID service, the default will be used, otherwise you can send as a parameter in this startSearch methods.
// Starting search for services in a found device
ServiceDiscoverer.getInstance().startSearch(remoteDeviceFound, new ServiceSearchListenerImpl());
Connect and start
//Creates a client configuration using the specific ServiceRecord found by ServiceSearcher
ClientConfiguration clientConfig = new ClientConfiguration(serviceRecord, CommunicationListenerImpl);
//Create a protocol factory to get the client
CommunicationFactory factory = new RFCOMMCommunicationFactory();
//Gets the client device instance
ClientDevice device = factory.connectToServer(clientConfig);
Exchange messages
Both server and device needs to startListening the messages and then can send messages using send method.
// Starting listening for incoming messages
device.startListening();
// Device sending a message
device.send("Test message".getBytes());
// Closing connection
device.close();
AutoConnect?
If you do not want to program the inquiry process, you can use AutoConnect?. Be sure the place that the application will run does not contain much Bluetooth devices and is running that the service that you want, otherwise AutoConnect? can take a long time to response back or can connect in another same service.
Create a server
//Creates a server. The service UUID will be generated by the name.
//The serverDevice will be returned by ConnectionListenerImpl.
AutoConnect.createServer("MargeBluechatServer", communicationListenerImpl, connectionListenerImpl);
Client connects to a server
//Creates a server. The service UUID will be generated by the name.
ClientDevice device = AutoConnect.createServer("MargeBluechatServer", communicationListenerImpl);
Layer
If you want special behavior in the messages exchanged, you can use the new concept of layer. It is still evolving to maybe something like a decorator. Currently, there is a unicast layer, if you want your device having this behavior, just extend UnicastMessageLayer?. After that, you can instantiate it passing a device and then use its methods to have the special behavior.
//send a message yo a specific address
unicastLayer.sendMessage(stringAddress, "Marge rocks!".getBytes());
//all the names on the server will be returned by receiveNameOnServer(String address, String name) method
unicastLayer.getNamesOnServer();
//you need to implement it
public abstract void receiveMessage(String from, byte[] message);
//you need to implement it.
public abstract void receiveNameOnServer(String address, String name);
-- Main.brunogh - 15 Mar 2008 |
|