Threads
Threads
int main(int argc, char *argv[]) // main - Concurrent TCP server for ECHO service
{
char *service = "echo"; // service name or port number
struct sockaddr_in fsin; // the address of a client
int alen; // length of client's address
WSADATA wsadata;
if (WSAStartup(WSVERS, &wsadata) != 0) errexit("WSAStartup failed\n");
msock = passiveTCP(service, 5);
while (1) {
alen = sizeof(fsin);
ssock = accept(msock, (struct sockaddr *)&fsin, &alen);
if (ssock == INVALID_SOCKET)
errexit("accept: error number\n", GetLastError());
if (_beginthread((void (*)(void *))TCPechod, 8000, (void *)ssock) < 0)
errexit("_beginthread: %s\n", strerror(errno));
}
return 1; // not reached
}