Socketsand Socket Address Structure
Socketsand Socket Address Structure
Socketsand Socket Address Structure
net/publication/283284085
CITATIONS READS
0 4,632
2 authors, including:
Mohit Mittal
Knowtion GmbH
75 PUBLICATIONS 708 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Mohit Mittal on 28 October 2015.
Mohit Mittal1
1
Assistant Professor,
Anand College of Engineering & Management, Kapurthala.
Tarun Bhalla2
2
Assistant Professor,
Anand College of Engineering & Management, Kapurthala.
Abstract:-In this paper specifies the concept of The parameters have different formats for
socket and socket address structures. In this, we have different protocols.
discussed how communication has been performed The network interface must support different
between two hosts and discussed the role of the sockets. protocols. These protocols may use different-
Sockets address of IPv4 and IPv6 is defined. The socket size variable for addresses and other fields. [3]
function call is also included which consists of various
main functions like socket, connect, listen, bind, accept
and close. It consists of two types of servers which uses
socket function.
structsockaddr_in
{
unit8_t sin_len; /* length of structure
(16 byte) */
sa_family_tsin_family; /*AF_INET*/
in_port_tsin_port; /* 16-bit TCP or UDP
port number, network byte ordered */
struct in6_addr {
unit8_t s6_addr[16]; /* 128-bit Ipv6
address, network byte ordered */
};
struct sockaddr_in6
{
unit8_t sin6_len; /* length of this structure
(24byte) */
sa_family_t sin6_family; /*AF_INET6*/
in_port_t sin6_port; /* 16-bit TCP or
UDP port number, network byte ordered */
}; [3]
On error: -1
Connect Function
intconnect(intsockfd,conststructsockaddr*servaddr,
IJE
socklen_taddrlen);
Accept is called by the TCP server to return the next Concurrent Server
completed connection from the front of the completed listenfd = socket(…);
connection queue. bind(listenfd,…);
listen(listenfd,…)
sockfd: This is the same socket descriptor as in for ( ; ; ) {
listencall. connfd = accept(listenfd, …);
If (( pid = fork()) == 0) { /* child*/
*cliaddr: used to return the protocol address of the close(listenfd);
connected peer process (i.e., the client process).[2] /* process the request */
close(connfd);
*addrlen: {this is a value-result argument} exit(0);
}
Before the accept call:We set the integer value pointed close(connfd); /* parent*/
to by *addrlento the size of the socket address structure }[3]
pointed to by *cliaddr;
Iterative Server
listenfd = socket(…);
on return from the accept call: This integer value bind(listenfd,…);
contains the actual number of bytes stored in the socket listen(listenfd,…)
address structure. for ( ; ; ) {
connfd = accept(listenfd, …);
Returns on success: a new socket descriptor /* process the request */
on error : -1 close(connfd);
}[3]
RT
The server will have one connected socket for each connect(sockfd, …)
client connection accepted. /* process the request */
When the server is finished with a client, the connected close(sockfd);[3]
socket must be closed.
Example: CONCLUSION
sfd= accept (sd, NULL, NULL); In this paper ,we have concluded that the socket
interface generally holds the communication between
the user and the kernel. Also the two different
if (sfd== -1) err_sys (“accept error”);[2] applications can be interfaced through the
communication network. In TCP socket calls, the client
Close Function sends the request to the server and the server performs
all the functions i.e. socket(), bind(), listen() and
intclose (intsockfd); accept(). In concurrent servers, multiple clients can be
handledat the same time, whereas in iterative server, the
server processes only one request before accepting the
Close marks the socket as closed and returns to the
next one. The Internet Protocol breaks all
process immediately.
communications into packets, finite-sized chunks of
data which are separately and individually routed from
sockfd: This socket descriptor is no longer useable.
source to destination.
Note – TCP will try to send any data already queued to
REFERENCES
the other end before the normal connection termination
sequence. [1] Elementary TCP Sockets UNIX Network
Programming Vol. 1, Second Ed.
Returns on success: 0 Stevens Chapter 4
on error : -1
http://www.cs.usfca.edu/~parrt/doc/java/Sockets-
Example: notes.pdf
close (sd); [2]
[2] UNIX Network Programming by W. Richard
Stevens, Prentice Hall,
www.ijert.org 4
International Journal of Engineering Research & Technology (IJERT)
ISSN: 2278-0181
Englewood Cliffs, NJ, 1997.
Vol. 1 Issue 8, October - 2012
http://web.cs.wpi.edu/~rek/Undergrad_Nets/B
06/TCP_Sockets.pdf
www.ijert.org 5
View publication stats