I'm trying to create a very simple client-server program. My aim is to send a message to the server after connecting succesfully but I need to be able to store the message using byteArrayOutputStream and also byteArrayInputStream later just in case something goes wrong along the way. This is my code so far:
public class TCPClient
{
public byte[] askServer(String hostname, int port, byte[] toServerBytes) throws IOException
{
Socket clientSocket = new Socket(hostname, port);
String Message;
StringBuilder sb = new StringBuilder();
try {
clientSocket.getOutputStream().write(toServerBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream fromClient = new ByteArrayOutputStream();
byte[] b = fromClient.toByteArray();
}