Why we have to get two file descriptors in TCP server socket programming? -


i take tutorial server socket programming link. functionality, have no problem that, , i'm asking more architecture design question. please take in tutorial. see 2 file descriptors, 1 when calling socket(), , 1 when calling accept(). makes sense why file descriptor when creating socket because treat socket file; makes sense have have multiple file descriptors when accepting different connections. why need have both make work?

the 1st socket called listening socket. tcp connection oriented stream. each client connection operates on own socket file. if have 1 socket, not able distinguish connection data received on belongs to. way tcp socket designed have listening socket operate in listen mode, , each time client want establish connection server, accept call return new socket, aka client socket, represent new connection, used communication client exclusively.

on other hand, udp connectionless datagram-based protocol, in 1 socket used handle data clients.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -