Development of Bluetooth from mobile phone to PC "2"--the communication between mobile phone and mobile phone is realized

Source: Internet
Author: User

The last article describes the development of the environment and some relevant knowledge of the introduction, this article is going to introduce how to achieve the mobile phone and mobile phone through the Bluetooth communication program, and then the next day may write a simple mobile phone via the Bluetooth internet games (other things more, plus the author more lazy, Oh, forgive me ~).

This small program is a C/s structure, but only one jar package. After running the program, the first page will have a two option (server or client), when you select the server, click the Select button will enter the server interface, click the Setup button, then open the server side of the program, and loop listening to the Bluetooth connection from the client; And if you choose the Client option, will enter the client interface, click Connect will start to search around the device and traverse the target services on the device, if the search to the service will be connected to the server, you can enter the text box and click to send information, the server will feedback the appropriate information.

Oh, although the realization of the function is simple, but want to do more complex applications, this step or must go ~ First look at my program file structure:

---core//CORE package name

---bluemessage.java//midlet main class, program entry

---components//Component Package name

---mainform.java//Start main interface (select client or server side here)

---blueclient.java//Client interface, inherit from form, implement Commandlistener interface

---blueserver.java//server-side interface, inherit from form, implement Commandlistener interface

---bluetooth

---blueclientservice.java//encapsulates a client-side Bluetooth service class that implements Runnable and Discoverylistener interfaces

---blueserverservice.java//encapsulates the server-side Bluetooth service class and implements the Runnable interface

Well, for the program file structure has a certain understanding, look at the next part of the code:

Bluemessage.java file:

/**

* MIDlet Application main class
* @author royen
* @since 2010.1.24
*/
public class Bluemessag          E extends MIDlet {
Public bluemessage () {
MainForm form=new mainform (this);
Display.getdisplay (This). Setcurrent (form);             
}
/**
* Exit Application
*/
public void Exitmidlet () {
try{
This.destroyapp (TRUE);
}
catch (Exception ex) {
System.out.println ("Occur Exception" +ex.getmessage ()); 
}


/**
* Navigating to other interfaces
* @param dis
*/
public void      NavigateTo (displayable dis) {
Display.getdisplay (this). setcurrent (dis);
}

protected void startApp () throws midletstatechangeexception {
}
protected void Destroyap P (Boolean arg0) throws Midletstatechangeexception {
}
Protectedvoid Pauseapp () {
//TOdo auto-generated Method stub}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.