Reputation: 89
I've read alot of other threads about UDP vs TCP but haven't really found any to correctly answer my question of design
The chat network that I'll be working on for a project will have 3 main applications: Client, Server, and a HUB(server).
The HUB server is the main server that connects all servers together to form a network. The Server will keep up with the chat rooms being made, in other words it will host the rooms. The Client will be used to connect to the servers to join chat rooms.
Now my main concern is when should I use UDP over TCP or vice versa when sending or executing requests from client to client, server to server, or server to client?
NOTE: This whole chat network project is 100% text-based, no graphics, webcam, mic, or file sharing functionality.
Upvotes: 2
Views: 2822
Reputation: 752
First of all you need to know what is TCP and UDP.
TCP
TCP is a connection-oriented protocol. Connection-orientation means that the communicating devices should establish a connection before transmitting data and should close the connection after transmitting the data.
So now you can see that TCP is a reliable protocol which will provide you the info/acknowledgement regarding the packet delivery and on the other hand UDP does not provide you the surety of 100% success on packet delivery.
For your case in chat service. My recommendation is to use TCP as in chats message delivery should be 100% success. And if packet delivery went failed then you can try to sent it again which somehow UDP does not feature with.
UDP can be used when doing some streaming over the network in that case UDP is best to go on with.
SO if you just have to chat between clients then preferable one will be TCP as there is a guarantee that the data transferred remains intact and arrives in the same order in which it was sent.
Upvotes: 0
Reputation: 87
As others have said, UDP does not guarantee packet delivery. However, if your HUB happens to be behind a NAT or firewall (as in a peer to peer network), then UDP provides advantages for getting around it. In your situation, this is the only reason I would use UDP. If you need reliable, in order delivery of packets, there are libraries such as UDT which can help with that.
Upvotes: 0
Reputation: 444
I did't understand the role of HUB server here? Are you allowing message passing between different chat rooms through HUB server?
As suggested by Steve, I will also recommend to go with TCP for a text based chat application. As in a text based chat application all messages should be delivered and in same sequence as they were sent.
Upvotes: 0
Reputation: 14699
UDP
is used when it's acceptable to lose some packets, in streaming, for example. In the case of a chat system, it's unacceptable to lose messages, so I would go with TCP
. For more information, see Difference between TCP and UDP? and When is it appropriate to use UDP instead of TCP?.
Upvotes: 5