I know this must be a pretty common problem, but I haven't been able to find a definitive answer on how to do it.
First, assume we have a java server that accepts queries such as (I've just put the relevant lines, and I've taken out the exception handling for clarity):
ServerSocket socket = new ServerSocket(port);
while (true) {
ClientWorker w;
w = new ClientWorker(socket.accept());
Thread t = new Thread(w);
t.start();
}
and then in the ClientWorker
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(client.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(client.getOutputStream());
String query = inFromClient.readLine();
// process query here
String response = "testresponse";
outToClient.writeBytes(response + "\n");
outToClient.close();
inFromClient.close();
client.close();
Right 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 a C++ client to do the same thing as the java client? I've tried many things but nothing seems to work. Ideally I wouldn't want to touch the java server, is that possible? If someone could point me to a good example or some sample code, that would be much appreciated. I searched through a lot of websites but to no avail.