luugiathuy / Remote-Bluetooth-Android

A simple remote bluetooth application for Android phone
MIT License
149 stars 152 forks source link

Send string data over the server #12

Open benoffi7 opened 8 years ago

benoffi7 commented 8 years ago

Hi! Its a great example to send commands but I need to send more information like strings or byts to decode in the server side.

Can U help me with the modifications on the server side when inputStream is read

inputStream.read

thanks!

benoffi7 commented 8 years ago

I can do this in the server

StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, "UTF-8");
String theString = writer.toString();
System.out.println(theString);

but this is the output

BlueCove version 2.1.1-SNAPSHOT on winsock
04c6093b00001000800000805f9b34fb
waiting for connection...
waiting for connection...
waiting for input
23456789?

finish process

in Android I send "123456789" with this code

public void write(String out) {
        // Create temporary object
        ConnectedThread r;
        // Synchronize a copy of the ConnectedThread
        synchronized (this) {
            if (mState != STATE_CONNECTED) return;
            r = mConnectedThread;
        }
        // Perform the write unsynchronized
        r.write(out.getBytes());
    }
benoffi7 commented 8 years ago

News!

I comment this line

int command = inputStream.read();

and I get the "full" string

123456789ÿ

I can eliminate the last char but is not the best...

benoffi7 commented 8 years ago

In my android app I have this

mCommandService.write(editText.getText().toString().trim());
editText.getText().clear();
mCommandService.stop();

If I remove the last line, the ÿ disapear. So I guess that is the stop command. Can I remove that or is native?