// pseudocode for a TCP (stream) server main() { s = socket() bind(s ...) listen(s ..) while (1) { newsock = accept(s ..) pthread_create(... connection ... ) } } connection() { while (1) { read(newsock ..) // or recv write(newsock ..) // or send } close(newsock); }