Sockets and concurrency 15-441 Spring 2010, Recitation 3 Your Awesome TAs.

Slides:



Advertisements
Similar presentations
Socket Programming Computer Networks, Spring 2008 Your TAs.
Advertisements

Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Sockets Programming Network API Socket Structures Socket Functions
Sockets Tutorial Ross Shaull cs146a What we imagine Network request… response… The packets that comprise your request are orderly.
Sop, Fan Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming.
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.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
I/O Multiplexing© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
1 Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write)
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
Event-Driven Programming Vivek Pai Dec 5, GedankenBits  What does a raw bit cost?  IDE  40GB: $100  120GB: $180  32MB USB Pen: $38  FireWire:
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.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
Introduction to Project 1 Web Client and Server Jan 2006.
Basic Networking & Interprocess Communication Vivek Pai Nov 27, 2001.
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)
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Today’s topic Other server design alternatives –Preforked servers –Threaded servers –Prethreaded servers.
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.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
Socket Models Different ways to manage your connections.
Scalable Kernel Performance for Internet Servers under Realistic Loads. Gaurav Banga, etc... Western Research Lab : Research Report 1998/06 (Proceedings.
Chapter 2 Applications and Layered Architectures Sockets.
Network Programming Eddie Aronovich mail:
Remote Shell CS230 Project #4 Assigned : Due date :
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.
OS2014 PROJECT 2 Supplemental Information. Outline Sequence Diagram of Project 2 Kernel Modules Kernel Sockets Work Queues Synchronization.
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.
Getting Started on Lab 1 Requirements MigratableProcess TransactionalFile{Input, Output}Stream ProcessManager MigratableProcesses.
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,
PA3: Improving Performance with I/O Multiplexing Part 1-1: Nov. 7, Part 1-2: Nov. 10 Part 2-1: Nov. 17, Part 2-2: Nov.20.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
Berkeley Socket Abstraction
LECTURE 10 Networking. NETWORKING IN PYTHON Many Python applications include networking – the ability to communicate between multiple machines. We are.
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 에서 사용.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
1 Network Communications A Brief Introduction. 2 Network Communications.
SPL/2010 Reactor Design Pattern 1. SPL/2010 Overview ● blocking sockets - impact on server scalability. ● non-blocking IO in Java - java.niopackage ●
@Yuan Xue CS 283Computer Networks Spring 2013 Instructor: Yuan Xue.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
SOCKET PROGRAMMING Presented By : Divya Sharma.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
I/O Multiplexing.
Input/Output.
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Java Byte IPC: Part 6-Summary
Advanced Sockets Introduction to Networking
Lecture 4 Socket Programming Issues
TCP Sockets Programming
Socket Programming.
Advanced UNIX programming
Server-side Programming CSE 333 Autumn 2018
Server-side Programming CSE 333 Summer 2018
Server-side Programming CSE 333 Winter 2019
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:

Sockets and concurrency Spring 2010, Recitation 3 Your Awesome TAs

Recitation Outline Sockets Reloaded Checkpoint 2 Project 1 Q&A General Q&A (A little throwback to Windows 3.1)

Revisiting Network Sockets Sockets, used for network IPC – How does this differ from IPC with two local processes? What did we need to setup for a socket? – Address of endpoint – Port associated with application How does reading/writing differ from file I/O? – read() not guaranteed to provide all requested data – Blocking much more of an issue

Socket Review Sockets are treated just like files: – socket() returns a file descriptor – read() & write(): same interface as for files Types of sockets – Blocking (synchronous) – Non-blocking Polling Asynchronous notification

Handling Connections Examples of network applications that rely on handling concurrent connections? – Web servers, file servers (AFS), IRC, AIM, etc… How can an application handle multiple connections? – Threading & select() Which do you have to use for all projects? – select()

Select() How select works – Allows you to monitor multiple sockets – API for monitoring multiple file descriptors Two main sets of descriptors – Read & write descriptors Use bit-array fd_set to monitor – fd_set readfds, writefds; First set all to 0 – FD_ZERO(&readfds); FD_ZERO(&writefds);

Telling Select What To Monitor After zeroing out, set FDs to be monitored – Original FD returned by socket() for incoming connections – All currently connected client’s FDs So, assuming sfd=socket(…); – FD_SET(sfd, &readfds); – Loop through client FDs: FD_SET(client[i].sfd, &readfds)

Using select() Select checks from bit 0 in the bit-array up until maxfd – Initially: maxfd=sfd; – Looping through clients: if(client[i].fds>maxfd) … Now, call it! – select(maxfd+1, &readfds, NULL, NULL, NULL);  IMPORTANT: select() overwrites &readfs with new bit-array, representing which file descriptors are ready

After Select() Returns Check the new bit-array What if select() sets the bit for sfd? – You have a new client – if (FD_ISSET(sfd, &readfds)) { accept_client(…); } What if select() sets the bit for a client FD? – Data is ready to be read – Must loop through all of your client FDs with FD_ISSET, if it’s set: handle_input(…)

I’ve handled the whole array… After you’ve gone through and used FD_ISSET(): – Start all over! – FD_ZERO(&readfds); – FD_SET(sfd, &readfds); – … In other words, create a while(1) around this and loop and loop! – Remember: keep the while(1) loop thin

More on Accepting New Clients Whenever FDISSET(sfd, &readfds), you have a new client You use accept() on sfd and save the returned file descriptor as your new client’s FD Store all of these FDs and make sure to set them in readfds before you call select()

Recitation Outline Sockets Reloaded Checkpoint 2 Project 1 Q&A General Q&A (A little throwback to Windows 3.1)

Checkpoint 2 Available under “Assignments” What you need to do: – Handle concurrent connections (this lecture!) – Echo back any commands to the client – Avoid blocking, one client should not be able to stall server by sending a partial command – Handle a malicious client Sends you long data with no ‘\n’ … don’t crash! Handle gracefully (preferably truncating)

Recitation Outline Sockets Reloaded Checkpoint 2 Project 1 Q&A General Q&A (A little throwback to Windows 3.1)