Hi There!
I am developing a Java server to go along with an app, however i have run into the following problem:
I am using TCP to handle the client/server communication but for some reason, i am only able to send data to the Server but not receive a reply.
This is an example of my code which is super simple but for some reason doesn’t work and I am far beyond the point of staring myself blind, trying to fix it.
Lua:
function pushToServer(dataToSend)
local tcp = socket.tcp()
tcp:settimeout(2)
tcp:connect(xxxx, yyyyy);
tcp:send(dataToSend);
print(tcp:receive("*l"))
tcp:close()
end
Java:
// Read incoming
Socket clientSocket = serverSocket.accept();
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String jsonString = in.readLine();
// Reply
out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
out.write(stringToReturn);
I have debugged the code enough to know that the java code is first executed when the Lua client’s connection is closed, and I cant seem to figure out why. The Server succesfully reads the data from the Lua client, but first when the client closes the connection. Then the Server writes a reply but cant, because the connection is closed, and so the client receives NIL.
I am convinced that the problem is probably really simple and i am just making a newbie mistake so i hope some of you ninjas can help.
Thanks in advance
Jens Finneurp