Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Difference between networking programming and socket programming Ask Question.
Asked 10 years, 1 month ago. Active 7 years, 8 months ago. Viewed 24k times. Are there some topics that cover "network programming" but not "socket programming"? Improve this question. Add a comment. Active Oldest Votes. Improve this answer.
Jerry Coffin Jerry Coffin Thanks, now this is an answer worth upvoting. AnishaKaul: See edited answer. JerryCoffin: Possibly worth noting that sockets are a subset of IP-based protocols too.
On the client-side: The client knows the hostname of the machine on which the server is running and the port number on which the server is listening. To make a connection request, the client tries to rendezvous with the server on the server's machine and port.
The client also needs to identify itself to the server so it binds to a local port number that it will use during this connection. This is usually assigned by the system.
If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.
On the client side, if the connection is accepted, a socket is successfully created and the client can use the socket to communicate with the server. A socket is one endpoint of a two-way communication link between two programs running on the network. Server forms the listener socket while client reaches out to the server. This is the same number which appears on protocol field in the IP header of a packet.
This is completely optional, but it helps in reuse of address and port. Listen: int listen int sockfd, int backlog ; It puts the server socket in a passive mode, where it waits for the client to approach the server to make a connection.
The backlog, defines the maximum length to which the queue of pending connections for sockfd may grow. At this point, connection is established between client and server, and they are ready to transfer data. Stages for Client. The connect system call connects the socket referred to by the file descriptor sockfd to the address specified by addr. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.
See your article appearing on the GeeksforGeeks main page and help other Geeks.
0コメント