Sockets is a method for communication
between a client program and a server
program in a network. A socket is defined
as "the endpoint in a connection.
Sockets are created and used with a set of
programming requests or "function calls" sometimes
called the sockets application programming interface
(API).
What are the two types of sockets?
Stream Sockets
Annotations:
A stream socket is like a phone call -- one side places the call, the other answers, you say hello to each other (SYN/ACK in TCP), and then you exchange information. Once you are done, you say goodbye (FIN/ACK in TCP). If one side doesn't hear a goodbye, they will usually call the other back since this is an unexpected event; usually the client will reconnect to the server. There is a guarantee that data will not arrive in a different order than you sent it, and there is a reasonable guarantee that data will not be damaged.
Stream sockets are reliable two-way connected
communication streams. If you output two items into
the socket in the order "1, 2", they will arrive in the
order "1, 2" at the opposite end. They will also be error
free.
the telnet application, yes? It uses stream sockets.
All the characters you type need to arrive in the
same order you type them, right? Also, web
browsers use the HTTP protocol which uses stream
sockets to get pages.
A stream socket is like a phone call -- one side places the call, the other answers, you say hello to each
other (SYN/ACK in TCP), and then you exchange information. Once you are done, you say goodbye
(FIN/ACK in TCP). If one side doesn't hear a goodbye, they will usually call the other back since this is an
unexpected event; usually the client will reconnect to the server. There is a guarantee that data will not
arrive in a different order than you sent it, and there is a reasonable guarantee that data will not be
damaged.
So you use a stream socket when having information in
order and intact is important. File transfer protocols are a
good example here. You don't want to download some file
with its contents randomly shuffled around and damaged!
Stream sockets uses TCP
Datagram Sockets
A datagram socket is like passing a note in class. Consider the case where you are
not directly next to the person you are passing the note to; the note will travel from
person to person. It may not reach its destination, and it may be modified by the
time it gets there. If you pass two notes to the same person, they may arrive in an
order you didn't intend, since the route the notes take through the classroom may
not be the same, one person might not pass a note as fast as another, etc.
You'd use a datagram socket
when order is less important than
timely delivery
How do stream sockets achieve
this high level of data transmission
quality? They use a protocol called
"The Transmission Control
Protocol", otherwise known as
"TCP"
TCP
TCP is known as a connection-oriented protocol, which
means that a connection is established and maintained
until such time as the message or messages to be
exchanged by the application programs at each end have
been exchanged
TCP is responsible for ensuring that a message is divided into the packets
that IP manages and for reassembling the packets back into the complete
message at the other end. In the Open Systems Interconnection (OSI)
communication model, TCP is in layer 4, the Transport Layer.
Reliability: TCP is connection-oriented protocol. When a file or
message send it will get delivered unless connections fails. If
connection lost, the server will request the lost part. There is
no corruption while transferring a message.
Ordered: If you send two messages along a connection,
one after the other, you know the first message will get
there first. You don't have to worry about data arriving in
the wrong order
Heavyweight: - when the low level parts of the TCP "stream"
arrive in the wrong order, resend requests have to be sent,
and all the out of sequence parts have to be put back together,
so requires a bit of work to piece together
Streaming: Data is read as a "stream," with nothing distinguishing
where one packet ends and another begins. There may be
multiple packets per read call.
TCP is one of the main protocols in TCP/IP networks. Whereas the IP
protocol deals only with packets, TCP enables two hosts to establish a
connection and exchange streams of data. TCP guarantees delivery of
data and also guarantees that packets will be delivered in the same order
in which they were sent
Annotations:
Transmission Control Protocol
TCP is Internet Protocol, which is a set of networking protocols that
allows two or more computers to communicate.
Transmission Control Protocol knows as TCP.
UDP
UDP (User Datagram Protocol) is a
communications protocol that offers a limited
amount of service when messages are
exchanged between computers in a network that
uses the Internet Protocol (IP).
UDP (User Datagram Protocol) is a simple OSI transport layer
protocol for client/server network applications based on
Internet Protocol (IP). UDP is the main alternative to TCP and
one of the oldest network protocols in existence, introduced in
1980.
UDP network traffic is organized in the form of datagrams.
A datagram comprises one message unit. The first eight
(8) bytes of a datagram contain header information and the
remaining bytes contain message data.
Like the Transmission Control Protocol, UDP uses the Internet
Protocol to actually get a data unit (called a datagram) from one
computer to another. Unlike TCP, however, UDP does not provide
the service of dividing a message into packets (datagrams) and
reassembling it at the other end. other en
UDP provides two services not provided by the IP
layer. It provides port numbers to help distinguish
different user requests and, optionally, a checksum
capability to verify that the data arrived intact.
In the Open Systems Interconnection (OSI) communication
model, UDP, like TCP, is in layer 4, the Transport Layer.
Reliability: UDP is connectionless protocol. When
you a send a data or message, you don't know if it'll
get there, it could get lost on the way. There may be
corruption while transferring a message.
Ordered: If you send two messages out, you don't
know what order they'll arrive in i.e. no ordered
Datagrams: Packets are sent individually and
are guaranteed to be whole if they arrive. One
packet per one read call.
Lightweight: No ordering of messages, no tracking connections, etc. It's
just fire and forget! This means it's a lot quicker, and the network card /
OS have to do very little work to translate the data back from the
packets.