Android Open Source - BluetoothRecord B T Server






From Project

Back to project page BluetoothRecord.

License

The source code is released under:

Apache License

If you think the Android project BluetoothRecord listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.audioserver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
  /*w  ww .j a v a  2s .  co  m*/
import javax.bluetooth.*;
import javax.microedition.io.*;
  
/**
* Class that implements an SPP Server which accepts single line of
* message from an SPP client and sends a single line of response to the client.
*/
public class BTServer {
    
    //start server
    public void startServer() throws IOException{
  
        //Create a UUID for SPP
        UUID uuid = new UUID("1101", true);
        //Create the service url
        String connectionString = "btspp://localhost:" + uuid +";name=Laptop Mic";
        
        //open server url
        StreamConnectionNotifier streamConnNotifier = (StreamConnectionNotifier)Connector.open( connectionString );
        
        //Wait for client connection
        System.out.println("\nServer Started. Waiting for clients to connect...");
        StreamConnection connection=streamConnNotifier.acceptAndOpen();
  
        RemoteDevice dev = RemoteDevice.getRemoteDevice(connection);
        System.out.println("Remote device address: "+dev.getBluetoothAddress());
        System.out.println("Remote device name: "+dev.getFriendlyName(true));
        
        //read string from spp client
        InputStream inStream=connection.openInputStream();
        BufferedReader bReader=new BufferedReader(new InputStreamReader(inStream));
        String lineRead=bReader.readLine();
        getCommand(lineRead);
        
        //send response to spp client
        OutputStream outStream=connection.openOutputStream();
        PrintWriter pWriter=new PrintWriter(new OutputStreamWriter(outStream));
        pWriter.write("Response String from SPP Server\r\n");
        pWriter.flush();
  
        pWriter.close();
        streamConnNotifier.close();
  
    }
    private void getCommand(String command){
      System.out.println(command);
      
    }
}




Java Source Code List

com.audioseparate.AudioSampleReader.java
com.audioseparate.AudioSep.java
com.audioseparate.BTConnect.java
com.audioseparate.MainActivity.java
com.audioseparate.Record.java
com.audioseparate.SingleWaveformPanel.java
com.audioseparate.WaveformPanelContainer.java
com.audioserver.BTServer.java
com.audioserver.ServerCommand.java