Socket Programming
IP Address: IP address is used to identify the host
on a network.
Port Address: Port address is used to identify the
process on the host. For example, port 80 is used for HTTP traffic, port 23 is
used for telnet.
What is Socket?
Sockets are
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). The
most common sockets API is the Berkeley UNIX C interface for sockets. Sockets can also be used for
communication between processes within the same computer.
A socket is
one end-point of a two-way communication link between two programs running on
the network.
On the
client-side: The client knows the hostname of the machine on which the server
is running and the port number on which the server is listening. To make a
connection request, the client tries to rendezvous with the server on the
server's machine and port.
If
everything goes well, the server accepts the connection.
On the
client side, if the connection is accepted, a socket is successfully created
and the client can use the socket to communicate with the server.
Why need Socket?
A socket is an IP address and a port address. Sockets exist
within communication domains and allow for bi-directional, reliably, and
sequenced data flow. When used in the client/server model, it allows programs
such as FTP and Telnet to function properly.
Example: A Telnet
server listens at port 23 for service requests. Telnet will remain inactive
until a client connects to the servers IP address. This request would be passed
up the stack to the appropriate port (23). At that moment, the server would
wake up and perform whatever has been requested by the client.
Therefore, without an IP address, the client would not be
able to find the server or without the correct port, the client couldn’t find
the need server services.
No comments:
Post a Comment