N 개를 수신하고이 데이터 배치를 처리하여 모든 클라이언트에게 "완료"한 답장을 보낼 때까지 여러 클라이언트의 메시지를 수락하는 서버를 작성하려고합니다.소켓 : 여러 클라이언트에 메시지 보내기
클라이언트에서 데이터를받은 직후에 클라이언트에 "완료"메시지를 보내면이 코드가 제대로 작동합니다. 어떻게하면 모든 클라이언트를 "저장"하고 나중에 배치를 처리 한 후에 메시지를 각각 보낼 수 있습니까?
while (true) {
listen(sock, 1000);
newsock = accept(sock, (struct sockaddr *) &cli_addr, &clilen);
n = read(newsock, buffer, read_len);
if (n < 0) {
cout << "ERROR reading from the socket" << endl;
continue;
}
memcpy(data + (msg_count * tuple_size), buffer, tuple_size);
n = write(newsock, "done\n", 5); //sending the message to the current client
msg_count++;
if (msg_count >= batch_size) {
msg_count = 0;
doSomethingWithTheData(data);
//I want to send the message to all the clients here
}
bzero(buffer, read_len);
}
쿠키 설정을 시도 했습니까? – Arash
@ArashMohammadi 아니, 나는 그들을 시도하지 않았다, 나는 그것에 대해 지금 읽을거야. 서버와 모든 클라이언트가 동일한 PC에있는 경우 쿠키가 작동합니까? – vgeclair
클라이언트가 하나 이상의 메시지를 보낼 수 있다면,'select' 나'epoll'을 조사 할 수 있습니다. – user4581301