I'm using an SSL connection to connect with a server (which i have no control over and no access to it's code, could be it's fault, but i wanna be sure), when i send the data (a byte array) for the first time i get the correct response, but in subsequent sends i get the response expected by the previous send. for example, let's say if i send x, i expect the server to reply x, y to y, z to z, etc...
when the app starts, i call x, and get x. but then i call y and get x, call z and get y, call x and get z, etc... here's the generic code implemented for each command to send and receive (bytes is initiated with a predetermined set of bytes to simulate, say, command x)
byte[] bytes = new byte[6];
if(socket == null || !socket.isConnected() || socket.isClosed())
try {
getSocket(localIp);
} catch (IOException e1) {
e1.printStackTrace();
}
if (socket == null || !socket.isConnected()) {
try {
getSocket(globalIp);
} catch (IOException e1) {
e1.printStackTrace();
return null;
}
}
byte[] recievedBytes = null;
String sentBString = "sendGetConfig: ";
for (int i = 0; i < bytes.length; i++) {
sentBString += String.valueOf(bytes[i]) + ", ";
}
System.out.println(sentBString);
if (socket != null){
try {
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
os.write(bytes);
DataInputStream is = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
int tries = 0;
while (tries < 20 && (recievedBytes == null || recievedBytes.length == 0)) {
if (is.markSupported()) {
is.mark(2048);
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
try {
nRead = is.read(data, 0, data.length);
buffer.write(data, 0, nRead);
} catch (Exception e) {
}
buffer.flush();
recievedBytes = buffer.toByteArray();
if (recievedBytes.length == 0)
is.reset();
}
is.close();
os.close();
socket.close();
}
}
i know the implementation of the read is not perfect, its the result of a workaround i did because the server does not send any end of stream indication and so any read command implemented in a loop results in a timeout exception
any help will be greatly appreciated