私は現在、RMI サーバー (C) のクライアントである Java サーバー (B) と通信する C クライアント (A) に取り組んでいます。A は引数を B に送信する必要があり、B はそれらを C に送信し、C はそれらを処理して B に再送信し、B はそれらを A に返します。したがって、明らかに A はソケットに書き込み、B が何かを送信するまでブロックされたままにする必要があります。戻る。私が直面している問題は、A がソケットに書き込み、select() によってブロックされたままになった後、B が独自の readLine からブロック解除されないことです。
A から select() と read() を削除すると、すべてが完全に機能します。これがコードです
A-client.c
int err;
err = send(sockfd,(const char*)toSend,size,0);//send counter
if (err < 0){
perror("Problem encountered while sending");
exit(3);
}
//it always gets past this line
fd_set read_set;
int nb;
FD_ZERO(&read_set); //initialize variables for select
FD_SET(sockfd, &read_set);
nb = select(sockfd+1, &read_set, NULL, NULL, NULL);
if (nb!=0){
if (FD_ISSET(sockfd, &read_set)) {//if data is incoming from*/
char word[4096]="";
if (read(sockfd, word, 4096) == 0){
perror("The server terminated prematurely");
exit(4);
}
for (i=0;i<4096;i++){
printf("%c",word[i]);
}
}
}
B-server.Java
connection = socket1.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//it always passes this line
String str = br.readLine();
//it passes this line only if i kill the C client or remove the read and select from the client
String[] splitStr = str.split("\\s+");
int argsLen = splitStr.length;