0
Cサーバから文字列(char ** topics
)の配列をJavaクライアントに送信しようとしています。どうやら、サーバーはトピックを適切に送信しますが、クライアントは受信しません。CサーバからJavaクライアントへのメッセージの送信
/* SERVER */
while (*topics != NULL) {
printf(" > Sending topic '%s'.. ", *topics);
if(write(sd, *topics, sizeof(*topics)) == -1) {
perror("write");
exit(1);
}
printf("[OK]\n");
topics++;
}
クライアントは次のようになります。
/* 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);
}
}
クライアントが
s> Current Topics:
を示し、待っているのまま...:/
Cの 'sizeof'演算子について知りたいかもしれません。 – Olaf
Cサーバーはストリーム上に改行文字を送りますか?これは 'readLine'がJavaでブロックしているものです。 – rgettman
トピックの最後に "\ n"を連結しようとしましたが、それでも同じです – nash