I'm trying to send an array of string (char ** topics) from a C server to a Java client. Apparently, the server sends the topics properly, but the client does not receive them.
/* SERVER */ while (*topics != NULL) { printf(" > Sending topic '%s'.. ", *topics); if(write(sd, *topics, sizeof(*topics)) == -1) { perror("write"); exit(1); } printf("[OK]\n"); topics++; } The client looks like this:
/* CLIENT */ static void server_connection() { String topic = null; try { Socket _sd = new Socket(_server, _port); // Socket Descriptor // Create input stream DataInputStream _in = new DataInputStream(_sd.getInputStream()); BufferedReader _br = new BufferedReader(new InputStreamReader(_in)); System.out.println("s> Current Topics:"); while ((topic = _br.readLine()) != null) { System.out.println(topic); } if(topic == null) { System.out.println("Not topics found"); } // Close socket connection _out.close(); _in.close(); _sd.close(); } catch(IOException e) { System.out.println("Error in the connection to the broker " + _server + ":" + _port); } } The client shows
s> Current Topics: and remains waiting... :/
sizeofoperator in C.readLineis blocking on in Java.write(sd, '\n', 1);and get enlightened.