Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.DataInputStream;
- import java.io.IOException;
- import javax.bluetooth.RemoteDevice;
- import javax.bluetooth.UUID;
- import javax.microedition.io.Connector;
- import javax.microedition.io.StreamConnection;
- import javax.microedition.io.StreamConnectionNotifier;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.midlet.MIDletStateChangeException;
- /*
- * To change this template, choose Tools | Templates and open the template in
- * the editor.
- */
- /**
- *
- * @author Smith
- */
- public class Server22 extends MIDlet {
- private static final String myServiceName = "MyBtService";
- private static final String myServiceUUID = "2d26618601fb47c28d9f10b8ec891363";
- private UUID MYSERVICEUUID_UUID = new UUID(myServiceUUID, false);
- public Server22() throws IOException {
- String connURL = "btspp://localhost:" + MYSERVICEUUID_UUID.toString() + ";" + "name=" + myServiceName;
- StreamConnectionNotifier scn = (StreamConnectionNotifier) Connector.open(connURL);
- StreamConnection sc = scn.acceptAndOpen();
- RemoteDevice rd = RemoteDevice.getRemoteDevice(sc);
- System.out.println("New client connection... "
- + rd.getFriendlyName(false));
- // Read input message, in this example a String
- DataInputStream dataIn = sc.openDataInputStream();
- while(true){ String s = dataIn.readUTF();
- System.out.println(s);
- }
- }
- protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
- }
- protected void pauseApp() {
- }
- protected void startApp() throws MIDletStateChangeException {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement