Socket Programming:
"An application programming interface (ATI) use for interprocess communication (IPC). A well defined method of connecting two process locally or across a network it is protocol and language interdependent and often referred as Berkeley socket or BSD Socket."
Socket is
protocol independent method of creating a connection between processes Socket can
be either connection based or connection pocket based or streams based reliable
or unreliable.
Socket
Characteristics:
Sockets are
characterized by their domain type and transport protocol common are
AF UNIX-
Address format is UNIX path name.
AF INET-
Address format is host and port number.
Common types are
A)
Virtual
circuit: received in order transmitted and reliability
B)
Data
gram: arbitrary order unreliable each socket type has one or more protocol
a)
TCP/IP
b)
UDP
Use Of Sockets
I Connection based socket
communicate silent server waits for a connection silent server connection less
socket are peer to peer each process is symmetric
This list is a summary of
function or methods provide by the berkets sockets API library
1)
Socket
create a new socket type identify by an integer number and allocates system
resource to it.
2)
Bind
is typically use on the server side and associates a sockets with a socket address
structure specified local port number and IP address.
3)
Listen
is use on the silent side and assign a free local part no to socket in case of
TCP socket to enter listing state
4)
Connect
is use on the silent side assignment a free local part no to a socket in case
of TCP socket if cause an attempt to
established a TCP connection
5)
Accept is used on the server side it accepted a
receive incoming attempt to create a new TCP connection from the remote to
create a new socket associate with the socket address pair this connection
6)
Send
and receive or read write or send to and received form
are used for sending and receiving data to from a remote socket.
7)
Close
cause the system to release resources allocated to socket in case TCP the
connection is terminated
8)
Get
host by address & get host by name
are used to resolve host name a address IP V4 only
9)
Select
is used to Pune a provided list of sockets for those that are ready to read,
ready to write or that have error.
10)
Poll
is used to check on the state of socket of socket in set of socket the set can
be tested to see if any socket can be
written to read from or if an error occurred
11)
Get
sock opt is used to retrieve the current value of a particular socket option
for the specified socket.
12)
Set
sock opt is used to set a particular socket option for the specified socket.
Client server example
using TCP
The transmission control protocol TCP is a connection –
oriented protocol that provides a variety of error correction & performance
feature for transmission of byte stream. A process- INNET, PF – INET6, the
socket made for stream ssockets ( sock- STREAM), & the IP protocol
identifier for TCPC(IP PROTO-TCP)
Server
Setting up a simple TCP server involves the following steps
Creating a TCP socket with a call to socket binding the
socket to the listen part with a call to bind before calling blind a Programmer
must clear a scokaddr- in structure , Clear it with memset c & the sin
family (AF-INET), & fill its sin – port ( the listening port, in network
byte order fields. Converting a short int to network byte order can be done by
calling the function h tons() ( host to network listen. Accepting incoming
connection, via a call to accept. This blocks until an incoming connection is
received and then return a socket description for the accept can be called
again at any time with this socket, until it is closed. Communicating with the
remote host, which can be done through send and receive or write and read.
Eventually closing each socket that was opened, once it is no longer needed,
using close.
Client
Programming a TCP client application involves the following
steps:
1
Creating
a TCP socket, with a call to socket.
2
Connection
to the server with a call the use of connect passing a sockaddr_ in structure
with the sin family set to AF_INET, sin port set to the port the end point is
listening (in n/w byte order), & sin _ addr set to the IP addr of listening
server (also in n/w byte order), & sin _ addr set to the IP addr of
listening server (also in n /w byte order).
3
Communicating
with the server by using send & receive or write & read.
4
Terminating
the connecting & cleaning up with a call to close.
Basics of Multiplexing
Difference between Multiplexing and Multiple Access
Comparison in FDM and synchronus TDM and statistical TDM
How Multiplexing of signals in Fiber Optical cable is done?