Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send string data over the server #12

Open
benoffi7 opened this issue Sep 14, 2016 · 3 comments
Open

Send string data over the server #12

benoffi7 opened this issue Sep 14, 2016 · 3 comments

Comments

@benoffi7
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant