Bei der Verwendung von Sockets bin ich mir nicht sicher, wie ich das Timeout einstellen soll?
Danke
int sock, connected, bytes_recieved;
char send_data [128] , recv_data[128];
SOCKADDR_IN server_addr,client_addr;
int sin_size;
int j = 0;
::socket(AF_INET, SOCK_STREAM, 0);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(4000);
server_addr.sin_addr.s_addr = INADDR_ANY;
::bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
::listen(sock, 5);
::fflush(stdout);
while(1)
{
sin_size = sizeof(struct sockaddr_in);
connected = ::accept(sock, (struct sockaddr *)&client_addr, &sin_size);
while (1)
{
j++;
::send(connected, send_data, strlen(send_data), 0);
// dealing with lost communication ?
// and reestablishing communication
// set timeout and reset on timeout error
}
}
::closesocket(sock);