C
nun, ich weiss nicht ob es jemanden interessiert, doch habe ich den fehler gefunden und das problem geloest. ich poste den neuen quelltext, da es spaeter vielleicht mal jemandem helfen koennte. [ist das resourcenverschwendung, sollen es die admins loeschen]
while (1) {
FD_ZERO(&readfds);
FD_SET(sock_listen, &readfds);
for (i=0; i<MAXCLIENTS; i++) {
if (index[i] != INVALID_SOCKET) {
FD_SET(index[i], &readfds);
}
}
if (select(0, &readfds, NULL, NULL, NULL) == SOCKET_ERROR) {
printf("select()...error %d\n", WSAGetLastError());
} //select()...successful geloescht, da bei jedem loop ausgegeben
if (FD_ISSET(sock_listen, &readfds)) {
printf("new connection...\n");
for (i=0; i<MAXCLIENTS; i++) {
if (index[i] == INVALID_SOCKET) {
structlen = sizeof(their);
if ((index[i] = accept(sock_listen, (struct sockaddr *)&their,&structlen)) == SOCKET_ERROR) {
printf("accept()...error %d\n", WSAGetLastError());
} else {
printf("accept()...successful, client %d\n", index[i]);
}
break; //gehoert hier her, da sonst kein valider socket gefunden wird
}
}
}
for (i=0; i < MAXCLIENTS; i++) {
if (index[i] == INVALID_SOCKET) {
continue;
}
if (FD_ISSET(index[i], &readfds)) {
recvd = recv(index[i], get, MAXDATA, 0);
if (recvd == 0 || recvd == SOCKET_ERROR) {
printf("recvd()...client %d closed connection", index[i]);
closesocket(index[i]);
FD_CLR(index[i], &readfds);
index[i] = INVALID_SOCKET; //nicht vergessen sockdescriptor auch zu loeschen
} else {
get[recvd] = '\0';
printf("recvd()...%d byte data recieved from client %d\n", recvd, index[i]);
printf("\trevieved data: %s\n", get);
for (j=0; j < MAXCLIENTS; j++) {
if (index[j] == INVALID_SOCKET) {
continue;
}
if (FD_ISSET(index[j], &readfds)) {
if(index[j] != index[i]) {
if (send(index[j], get, recvd, 0) == -1) {
printf("send()... error %d\n", WSAGetLastError);
} else {
printf("send() data to %d\n", index[j]);
}
}
}
}
}
}
}
}
gruss caspar