Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.

Slides:



Advertisements
Similar presentations
Nonblocking I/O Blocking vs. non-blocking I/O
Advertisements

Socket Programming. Basics Socket is an interface between application and network – Application creates a socket – Socket type dictates the style of communication.
Sop, Fan Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming.
I/O Models Satish Krishnan. I/O Models Blocking I/O Non-blocking I/O I/O Multiplexing Signal driven I/O Asynchronous I/O.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Lecture 16 Overview. Creating a TCP socket int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen); int mysock; struct sockaddr_in myaddr;
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
TDC561 Network Programming Camelia Zlatea, PhD Week 3: Unix Asynchronous Events; Signals and Alarms API.
CS4514-Help Session By Huahui Wu. Description In this project, you are supposed to implement a PAR (Positive Acknowledgement with Retransmission)
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
I/O Multiplexing© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
I/O Multiplexing Capability of tell the kernel that wants to be notified when one or more I/O conditions are ready. For example, I/O data is available.
Network LayerDatalink LayerPhysical LayerNetwork LayerDatalink LayerPhysical Layer ClientServer Framework.
Lecture 8 UDP Sockets & I/O Multiplexing
1 CS4514 Project 2 Help Session (B05) Mingzhe Li Nov 10, 2005.
Select The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O. int select( int nfds, fd_set*
IP Multiplexing Ying Zhang EECS 489 W07.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
Project Assignment 1 Ying Zhang EECS 489 W07. Clarification Questions for each test Expected output for each test.
Elementary TCP Sockets
Today’s topic Other server design alternatives –Preforked servers –Threaded servers –Prethreaded servers.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
Chapter 2 Applications and Layered Architectures Sockets.
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
Socket Programming Using JAVA Asma Shakil Semester 1, 2008/2009.
1 COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
Sockets in C. 2 References Manual Pages %torch man –s 3socket … Socket, bind, listen, etc. %torch man –s 3c select Resources section of website.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
Practical Session 11 Multi Client-Server Java NIO.
Project 2: Socket Programming. Overview Sockets Working with sockets Client-Server example Project 1 Hints.
I/O Multiplexing. What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors,
Cs423-cotter1 Concurrency Issues in Client/Server Applications Chapters 15,16, 28.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
Today’s topic: UDP Reliable communication over UDP.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
CMPT 471 Networking II Network Programming © Janice Regan,
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
Ioctl Operations. ioctl Function Interface Configuration  Netstat, ifconfig command 에서 사용.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
I/O Multiplexing.
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Concurrent Servers Topics Limitations of iterative servers
Advanced Sockets Introduction to Networking
Lecture 4 Socket Programming Issues
CS4516 Program 2 Help Session (C10)
CS4514 Project 2 Help Session (B07)
Lecture 11 Overview.
TCP Sockets Programming
Advanced Network Programming spring 2007
Socket Programming.
TCP/IP Socket Programming in C
Issues in Client/Server Programming
Advanced UNIX programming
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Presentation transcript:

Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing

How to send/receive structures with TCP? –TCP provides a byte-stream service. –Two issues: Get the right size for the data Get the right format –Consider example1.c and example2.c,

Client/Server TCP Connection Sequence socket() connect() bind() listen() accept() socket() write() read() close() read() write() read()close() 3-way handshake EOF data Client Server

Sequential server socket() bind() listen() accept() read() write() read()close() Handle one connection at a time

Concurrent server: Use a new child process to handle a new connection request. When to fork? Advantages –simple program, most of the servers are implemented this way. –Almost no limits on the number of connection. Main limitations: too much overhead.

socket() bind() listen() accept() read() write() read()close() socket() bind() listen() Loop forever accept() fork Close accepted socket Close listen socket read() write() read()close() Sequential server Concurrent server (example2.c)

–What happens to the client when the server crushes? How to make the client to anticipate the problem (example1.c)? The real problem of this client: –The client has two places that can block. May not be able to detect that something is wrong. –Solution? »I/O multiplexing – check the file descriptor before performing a blocking operation. »Mechanism: select.

–The select function that allows: To detect any of the descriptors in the read set that are ready for reading. To detect any of the descriptors in the write set that are ready for writing To detect any of the descriptors in the error set that have exception conditions pending. To wait for a period for something to happen. #include int select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout)

#include int select (int maxfdp, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) –Set the timeout value: Struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ } Wait forever (blocking select): timeout = NULL Non blocking select (return right away: tv_sec = 0; tv_usec = 0; Wait for a certain amount of time: tv_sec and tv_usec

#include Int select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) –Set the set of file descriptors value: void FD_ZERO(fd_set *fdset) /* fdset = {} */ void FD_SET(int fd, fd_set *fdset) /* fdset = fdset + {fd} */ void FD_CLR(int fd, fd_set *fdset) /* fdset = fdset – {fd} */ void FD_ISSET(int fd, fd_set *fdset) /* fd in fdset? */ –Maxfdp1: the maximum file descriptor number plus 1. (can just specify a big number (64) if unknown). –Select clears the uninteresting file descriptors in the fd_sets – always reset the fd_sets before calling select.

When is a socket ready for read/write/exception? –Read: The number of bytes in the socket is more than the low-water mark (can be set, default 1 for TCP/UDP socket) Half of the connection is closed Listening socket with nonzero of completed connections Socket error. –Write: The available buffer space is larger than the low-water mark Half the connection is closed Error pending –Exception: Out of band data exists.

Now with the select function? How can we improve the client (example1.c)? –If server crushes, the client should know it right away!! –Trick: make a single point for blocking (program is sequential in nature). Block at select (allows monitoring many files and sockets), never block in reading. –See example3.c

With select, we can also implement a multiplexed server: –A single server thread to handle everything including connection requests, data transmissions and inputs from keyboard. –Block on select to check on all descriptors, and react accordingly Listen socket is active  accept Data socket is active –Read/write –Close socket if the other end has been closed Standard input is active  read and act accordingly –Book keeping: When a new connection arrives, put it in the set of descriptors to be monitored When a connection is closed, removed it from the set of descriptios to be monitored

socket() bind() listen() Loop forever select If listen socket is active  accept, book keeping If data socket is active: read/write If read returns 0, close the socket, book keeping If standard input is active: act accordingly Multiplexed server (example4.c)

Multiplexed server (example4.c): –Multiplexed server/concurrent server: which one is more efficient?