hi, i'm new on the C/C++ scene.
i want to make a socket listen & accept procedure during getch()
the problem is that both of them are blocking methods.
i know about select function, but i didn't manage to get it work (maybe because getch() is blocking it)
the idea is to make UI to the user, and simultaniously accept remote connections.
thanksCode:... ... void listener(int port) { struct timeval tv = { 0L, 0L }; fd_set acc; int s,siz; struct sockaddr_in m,remote; s = socket(AF_INET,SOCK_STREAM,0); m.sin_family = AF_INET; m.sin_port = htons(port); m.sin_addr.s_addr = INADDR_ANY; memset(&(m.sin_zero), '\0', 8); printf("asd"); bind(s, (struct sockaddr *)&m, sizeof(struct sockaddr)); listen(s,5); FD_ZERO(&acc); FD_SET(s, &acc); printf("%d",select(1, &acc, NULL, NULL, &tv)); // tried to debug and see the output, always equals 0 while(!select(1, &acc, NULL, NULL, &tv)) { siz=sizeof(struct sockaddr); accept(s, (struct sockaddr *)&remote, &siz); printf("accepted connection from %s",inet_ntoa(remote.sin_addr)); } } ... ... int main() { ... ... x: listener(123); printf("Press computer number to perform tasks, r to check connections or q to quit.\n"); inp = getch(); switch(inp) { ... ... ... goto x; ... }



LinkBack URL
About LinkBacks



