I'm trying to work with the UDP protocol, and I don't understand the difference between a UDP Server and a UDP Client. Don't they do the same thing ?
The UDP server:
- Runs first (to open a listen port)
- Opens a specific port
- Typically can accept multiple client connections
The UDP client:
- Runs second (assuming the server is already running)
- Indicates a specific target port
- Randomly (usually) choose a source port that the server will reply to
- Typically single-threaded and handles only one connection to the UDP server
In fact, it's not that much different from TCP, except there is no three-way handshake nor any flow-control and congestion-control.
It actually depends from what point you look.
From point of server/client architecture it is definitely different. You can refer to other answers.
From socket programming point, it is quite same. Since UDP is connection-less, both server and client would use same sendto
and recvfrom
methods. There is no such socket API that is unique for server or client only(talking about UDP). So I would prefer to call sides peers or sender/receiver instead of server/client.
To quote from Wikipedia's entry for Client-server model:
The server component provides a function or service to one or many clients, which initiate requests for such services.
Putting this into my own words: the difference between a server and a client is a practical one with notions like centralization and roles. Take the difference between a server at a restaurant and a client at the server's table. Depending on things like the restaurant, a client may also be the server like at a buffet where you get food for your family or friends. Either way, the entity providing the service at the time, can be considered the server and the entity receiving the service is conceptualized as the client.
A client-server model isn't the only model either but rather is considered a "sub-category of distributed peer-to-peer systems".
Hope this helps!
© 2022 - 2024 — McMap. All rights reserved.