You are on page 1of 2

Connectionless (UDP) vs Connection-Oriented (TCP) Servers

Programmer can choose a connection-oriented server or a connectionless server


based on their applications.
In Internet Protocol terminology, the basic unit of data transfer is a datagram. This
is basically a header followed by some data. The datagram socket is connectionless.
 User Datagram Protocol (UDP):
1. Is a connectionless.
2. A single socket can send and receive packets from many different
computers.
3. Best effort delivery.
4. Some packets may be lost some packets may arrive out of order.
 Transmission Control Protocol (TCP):
1. Is a connection-oriented.
2. A client must connect a socket to a server.
3. TCP socket provides bidirectional channel between client and server.
4. Lost data is re-transmitted.
5. Data is delivered in-order.
6. Data is delivered as a stream of bytes.
7. TCP uses flow control.
 It is simple for a single UDP server to accept data from multiple clients and reply.
 It is easier to cope with network problems using TCP.

Ref: http://www.tenouk.com/Module39a.html

Fork
Returns: 0 in child, process ID of child in parent, -1 on error

There are two typical uses of fork:


A process makes a copy of itself so that one copy can handle one operation while the other
copy does another task. This is typical for network servers. We will see many examples of this later
in the text.

A process wants to execute another program. Since the only way to create a new process is
by calling fork, the process first calls fork to make a copy of itself, and then one of the copies
(typically the child process) calls exec (described next) to replace itself with the new program. This
is typical for programs such as shells.

When a connection is established, accept returns, the server calls fork, and the child process
services the client (on connfd, the connected socket) and the parent process waits for another
connection (on listenfd, the listening socket). The parent closes the connected socket since the child
handles the new client.

Select:
This function allows the process to instruct the kernel to wait for any one of multiple events
to occur and to wake up the process only when one or more of these events occurs or when a
specified amount of time has passed.

#include <sys/select.h>
#include <sys/time.h>
int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval
*timeout);
Returns: positive count of ready descriptors, 0 on timeout, -1 on error

You might also like