I have a Socket connection to an application that I hosted elsewhere. Once I connected I made a
Once the connection has been made, I use the
OutputStream to send out a handshake packet to the application. Once this handshake has been approved, it returns a packet through the
This packet is processed and is returned to the application with the
If this returned data is valid, I get another packet from the
DataInputStream (2). However, I have not been able to read this packet through the
I have tried to use
DataInputStream.mark() but this gave me nothing (except for an empty Exception message).
Is it possible to read the input stream for a second time? And if so, can someone please point me out what I'm doing wrong here?
EDIT: Here is my solution:
// First define the Output and Input streams.
OutputStream output = socket.getOutputStream();
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
// Send the first packet to the application.
output.write("test"); // (not actual data that I sent)
// Make an empty byte array and fill it with the first response from the application.
byte incoming = new byte;
bis.read(incoming); //First packet receive
//Send a second packet to the application.
output.write("test2"); // (not actual data that I sent)
// Mark the Input stream to the length of the first response and reset the stream.
// Create a second empty byte array and fill it with the second response from the application.
byte incoming2 = new byte;
I'm not sure if this is the most correct way to do this, but this way it wo