I came up with a simple workaround
Client:
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args)
{
String hostAddress = "localhost";
int port = 8080;
Socket socket = null;
String test = "hello"; //decode bytes from this string on the server
byte[] byteArray = test.getBytes();
try
{
socket = new Socket(hostAddress, port);
OutputStream out = socket.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.write(byteArray, 0, byteArray.length);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Server:
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) throws SocketException
{
try
{
ServerSocket server = new ServerSocket(8080);
server.setSoTimeout(0);
Socket connectionToClient = server.accept();
InputStream is = connectionToClient.getInputStream();
DataInputStream dis = new DataInputStream(is);
int buffersize = connectionToClient.getReceiveBufferSize();
byte[] bytes = new byte[buffersize];
if(dis.read(bytes) > 0)
{
String s = new String(bytes);
System.out.print(s);
}
dis.close();
server.close();
}
catch(IOException e)
{
e.printStackTrace();
System.err.println("Server was terminated.");
}
}
}