With the code below, I'm not getting "daSHI" printed onto the console. Instead im getting "?????" printed.
To test, instead of using the socket's input/output streams, I created a FileInputStream and FileOutputStream writing/reading from the same file and "daSHI" was printed just fine.
However, when I use sock.getOutputStream and sock.getInputStream, it doesn't work for some reason. All I'm getting are question marks. Any ideas? Encoding Problems?
public void sendMessage(Socket sock) throws KVException {
OutputStream outStream;
InputStream inStream;
try{
byte[] b = {'d', 'a', 'S', 'H', 'I'};
outStream = sock.getOutputStream();
outStream.write(b);
sock.shutdownOutput();
inStream = sock.getInputStream();
for (int i = 0; i < b.length; i++) {
System.out.print("" + (char) inStream.read());
}
}
catch(IOException e){
KVMessage errorMessage = new KVMessage("resp", "Network Error: Could not send data");
throw new KVException(errorMessage);
}
}