I know this should be a fairly common problem, but I could not find a definitive answer on how to do this.
First, suppose we have a Java server that accepts requests such as (I just put the appropriate lines and I made sure to handle the exceptions):
ServerSocket socket = new ServerSocket(port);
while (true) {
ClientWorker w;
w = new ClientWorker(socket.accept());
Thread t = new Thread(w);
t.start();
}
and then in ClientWorker
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(client.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(client.getOutputStream());
String query = inFromClient.readLine();
String response = "testresponse";
outToClient.writeBytes(response + "\n");
outToClient.close();
inFromClient.close();
client.close();
Now I can get a java client that works with this server:
String query = "testquery";
Socket queryProcessorSocket = new Socket(queryIp,queryPort);
DataOutputStream queryProcessorDos = new DataOutputStream(queryProcessorSocket.getOutputStream());
BufferedReader queryProcessorReader = new BufferedReader(new InputStreamReader(queryProcessorSocket.getInputStream()));
queryProcessorDos.writeBytes(query + "\n");
String response = queryProcessorReader.readLine();
But how can I get the C ++ client to do the same thing as the java client? I tried a lot of things but nothing works. Ideally, I would not want to touch the java server, is this possible? If someone can point me to a good example or some sample code, that would be very appreciated. I have looked at many websites, but to no avail.