Advertisement
Guest User

Server

a guest
Jul 23rd, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1.  
  2. import java.io.DataInputStream;
  3. import java.io.IOException;
  4. import javax.bluetooth.RemoteDevice;
  5. import javax.bluetooth.UUID;
  6. import javax.microedition.io.Connector;
  7. import javax.microedition.io.StreamConnection;
  8. import javax.microedition.io.StreamConnectionNotifier;
  9. import javax.microedition.midlet.MIDlet;
  10. import javax.microedition.midlet.MIDletStateChangeException;
  11.  
  12. /*
  13.  * To change this template, choose Tools | Templates and open the template in
  14.  * the editor.
  15.  */
  16. /**
  17.  *
  18.  * @author Smith
  19.  */
  20. public class Server22 extends MIDlet {
  21.  
  22.     private static final String myServiceName = "MyBtService";
  23.     private static final String myServiceUUID = "2d26618601fb47c28d9f10b8ec891363";
  24.     private UUID MYSERVICEUUID_UUID = new UUID(myServiceUUID, false);
  25.  
  26.     public Server22() throws IOException {
  27.         String connURL = "btspp://localhost:" + MYSERVICEUUID_UUID.toString() + ";" + "name=" + myServiceName;
  28.         StreamConnectionNotifier scn = (StreamConnectionNotifier) Connector.open(connURL);
  29.         StreamConnection sc = scn.acceptAndOpen();
  30.         RemoteDevice rd = RemoteDevice.getRemoteDevice(sc);
  31.         System.out.println("New client connection... "
  32.                 + rd.getFriendlyName(false));
  33.         // Read input message, in this example a String
  34.         DataInputStream dataIn = sc.openDataInputStream();
  35.       while(true){  String s = dataIn.readUTF();
  36.         System.out.println(s);
  37.       }
  38.      
  39.  
  40.     }
  41.  
  42.     protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
  43.     }
  44.  
  45.     protected void pauseApp() {
  46.     }
  47.  
  48.     protected void startApp() throws MIDletStateChangeException {
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement