Network Programming CSC- 341

Slides:



Advertisements
Similar presentations
Socket Programming 101 Vivek Ramachandran.
Advertisements

Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Programming with TCP – I
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
1 Elementary TCP Sockets socket function connect function bind function listen function accept function fork and exec functions Concurrent servers close.
Lecture 6 TCP Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
CSCE 515: Computer Network Programming TCP Details Wenyuan Xu Department of Computer Science and Engineering.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
Tutorial 8 Socket Programming
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Introduction to Project 1 Web Client and Server Jan 2006.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
ECE 4110 – Internetwork Programming Client-Server Model.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Elementary TCP Sockets
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Elementary TCP Sockets
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Chapter 2 Applications and Layered Architectures Sockets.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
Distributed Computing A Programmer’s Perspective.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Introduction to Sockets
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
Socket Programming Client/Server.
Socket Option.
Sockets and Beginning Network Programming
Read: Chapters 1,2, 3, 4 Communications Client Server Ex: TCP/IP
Elementary UDP Sockets
Network Programming CSC- 341
Chapter4 Elementary TCP Socket
Socket Programming in C
Transport layer API: Socket Programming
Chapter 2 Transport Layer Protocols TCP UDP SCTP
Network Programming CSC- 341
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
Socket Programming in C
TCP Sockets Programming
Advanced Network Programming spring 2007
Network Programming CSC- 341
Jan Ecs152b Behrooz Khorashadi
Server-side Programming CSE 333 Autumn 2018
Server-side Programming CSE 333 Summer 2018
Server-side Programming CSE 333 Winter 2019
Internet Networking recitation #8
Today’s topic: Basic TCP API
Presentation transcript:

Network Programming CSC- 341 Instructor: Junaid Tariq, Lecturer, Department of Computer Science

15 Lecture Network Programming

LISTEN FUNCTION

listen function #include <sys/socket.h> int listen(int sockfd, int backlog); Returns:0 if OK, -1 on error =>This function is called only by a TCP server and it performs two actions: Socket(active socket) to passive socket (accept request). In terms of TCP state diagram, listen moves the socket from CLOSED to LISTEN state. Second argument specifies the maximum number of connections that the kernel should queue for this socket.

listen function cont. To understand the backlog argument, we must realize that for a given listening socket, the kernel maintains two queues: An incomplete connection queue, which contains an entry for each SYN that has arrived from a client for which the server is awaiting completion of the TCP three-way handshake. These sockets are in the SYN_RCVD state (Figure 2.4). A completed connection queue, which contains an entry for each client with whom the TCP three-way handshake has completed. These sockets are in the ESTABLISHED state (Figure 2.4).

When a SYN arrives from a client, TCP creates a new entry on the incomplete queue and then responds with the second segment of the three-way handshake. This entry will remain in the incomplete queue until the third segment of the three- way handshake arrives, or until the entry times out. (Berkeley- 75 seconds.) If the three-way handshake completes normally, the entry moves from the incomplete queue to the end of the completed queue. When the process calls accept, the first entry on the completed queue is returned to the process, or if the queue is empty, the process is put to sleep until an entry is placed onto the completed queue.

listen function cont. There are several points to consider regarding the handling of these two queues The backlog argument to the listen function has historically specified the maximum value for the sum of both queues. There has never been a formal definition of what the backlog means. The 4.2BSD man page says that it "defines the maximum length the queue of pending connections may grow to." Berkeley-derived implementations add a fudge factor to the backlog: It is multiplied by 1.5 . For example, the commonly specified backlog of 5 really allows up to 8 queued entries on these systems, as we show in Figure 4.10. The reason for adding this fudge factor appears lost to history [Joy 1994]. But if we consider the backlog as specifying the maximum number of completed connections that the kernel will queue for a socket, then the reason for the fudge factor is to take into account incomplete connections on the queue.

Figure 4.10. Actual number of queued connections for values of backlog. listen function cont. Do not specify a backlog of 0, as different implementations interpret this differently.

listen function cont. Historically, sample code always shows a backlog of 5. This small number is inadequate in WWW. A problem is: What value should the application specify for the backlog, since 5 is often inadequate. There is no easy answer to this. It is always acceptable to specify a value that is larger than supported by the kernel, as the kernel should silently truncate the value to the maximum value that it supports, without returning an error. If the queues are full when a client SYN arrives, TCP ignores the arriving SYN; it does not send an RST.

ACCEPT FUNCTION

accept function #include <sys/socket.h> int accept(int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen); Returns:nonnegative descriptor if OK, -1 on error Return the next completed connection from the front of the completed connection queue. If queue is empty, the process is put to sleep.

accept function cont. The cliaddr and addrlen arguments are used to return the protocol address of the connected peer process. addrlen is a value-result argument. If accept is successful, its return value is a brand-new descriptor automatically created by the kernel. This new descriptor refers to the TCP connection with the client. we call the first argument to accept the listening socket, and we call the return value from accept the connected socket.

accept function cont. It is important to differentiate between these two sockets. A given server normally creates only one listening socket. The kernel creates one connected socket for each client connection that is accepted. This function returns up to three values: An integer return code that is either a new socket descriptor or an error indication, The protocol address of the client process (through the cliaddr pointer), and The size of this address (through the addrlen pointer). If we are not interested in having the protocol address of the client returned, we set both cliaddr and addrlen to null pointers.