1

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.

Steve P.
  • 14,489
  • 8
  • 42
  • 72
subless
  • 79
  • 1
  • 8

4 Answers4

4

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?.

Community
  • 1
  • 1
Steve P.
  • 14,489
  • 8
  • 42
  • 72
  • I'm thinking about designing the HUB server so that when I execute a command from it to gather information from a normal server, the normal server will just echo back the information to the hub, so i'll know when the request arrived. Would this example be a good choice for UDP cause I've heard that UDP is somewhat faster than TCP. – subless Aug 02 '13 at 05:05
  • Again, if you can tolerate some packet loss, then `UDP` can be a a good choice. Additionally, if all you want to do is deliver something very simple, then `UDP` may also be a good choice, but with respect to the delivery of the chat messages, I would go with `TCP`. Many of the answer provided in the two links are quite informative, check them out. – Steve P. Aug 02 '13 at 05:14
0

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.

Rupesh
  • 444
  • 3
  • 11
  • The HUB server is the main server that connects all other servers. But the HUB doesn't do any message passing, only the normal servers handle that. The HUB just connects the normal servers to form a network, that way I can keep each normal server updated with the chat room lists for users to choose from. – subless Aug 02 '13 at 22:28
0

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.

joshuaar
  • 87
  • 1
  • 7
0

First of all you need to know what is TCP and UDP.

  1. 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.

  2. UDP UDP is the Datagram oriented protocol. This is because there is no overhead for opening a connection, maintaining a connection, and terminating a connection. UDP is efficient for broadcast and multicast type of network transmission.

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.

Akhil Pathania
  • 542
  • 2
  • 5
  • 19