Creating a Bluetooth app, I have encountered an unexpected problem, that I cannot understand. PC acts as a server (java+bluecove), and Android phone is used as a client. Client connects to the server (which is confirmed by a message on the server side), server sends then a text sample, and that works fine. Next thing to do, is to send message to the server, and that part doesn't seem to work so far. I designed a button, thats task is to send short text message via Bluetooth. Server doesn't get the message.
A part of the activity sending message:
public void write(String message) {
OutputStreamWriter streamWriter = new OutputStreamWriter(pOutput);
try {
streamWriter.write(message);
streamWriter.flush();
} catch (IOException e) {
errorLog += "[SP:"+e.getMessage()+"]\n";
}
}
However, there is one more thing - as th Client application finishes all activities, the message is sent to the Server. Knowing that, I checked if adding streamWriter.close()
after flushing stream will do the trick. It works (message is sent), but since close()
method closes the socket as well, it doesn't suit me.
I don't understand the problem, can anyone give me an example or point the direction, please? There were topics about sockets, however they were solving wifi connection issues, and that doesn't seem much of a help.