Pertemuan 7 I/O Multiplexing

Slides:



Advertisements
Similar presentations
MERANCANG Program Transfer File (PTF) PTFServer dan PTFClient I Made Astawa
Advertisements

1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.
Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
1 Pertemuan 16 First & Second Conditionals Matakuliah: G0134 – Grammar III Tahun: 2005 Versi: revisi 1.
1 Pertemuan 22 Radix Sort Matakuliah: T0016/Algoritma dan Pemrograman Tahun: 2005 Versi: versi 2.
1 Pertemuan 6 Elementary UDP Sockets Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
Sop, Fan Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming.
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A TCP Connection is based on 6 crucial.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
15-441: Computer Networking Lecture 3: Application Layer and Socket Programming.
Lecture 16 Overview. Creating a TCP socket int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen); int mysock; struct sockaddr_in myaddr;
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Network Programming UNIX Internet Socket API. Everything in Unix is a File –When Unix programs do any sort of I/O, they do it by reading or writing to.
1 Pertemuan 10 Non Blocking Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
Socket Programming Sample Code - simple chat client and server ee122 sp05 daron spektor.
07 - Advertising Matakuliah: G0622/Bahasa Inggris 1 Tahun: 2005 Versi: 1.01.
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
11 - Innovation Matakuliah: G0622/Bahasa Inggris 1 Tahun: 2005 Versi: 1.01.
1 Pertemuan 20 Time & Condition Clauses with Future reference Matakuliah: G0134 – Grammar III Tahun: 2005 Versi: revisi 1.
1 Pertemuan 13 AVL Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
1 Pertemuan #3 Clocks and Realtime Matakuliah: H0232/Sistem Waktu Nyata Tahun: 2005 Versi: 1/5.
1 Pertemuan 25 Making It Happen Matakuliah: A0194/Pengendalian Rekayasa Ulang Informasi Tahun: 2005 Versi: 1/5.
Lecture 8 UDP Sockets & I/O Multiplexing
1 Pertemuan 8 The Object Definition Language (Lanjutan) Matakuliah: M0174/OBJECT ORIENTED DATABASE Tahun: 2005 Versi: 1/0.
IP Multiplexing Ying Zhang EECS 489 W07.
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A ‘reliable’ (but not secure!) protocol.
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.
Computer Network Sritrusta Sukaridhoto. Computer Network – Sritrusta Sukaridhoto Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
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.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Networking Concepts, Socket Programming Spring 2012.
1 Internet Socket programming Behzad Akbari. 2 Sharif University of Technology, Kish Island Campus What is an API? API – stands for Application Programming.
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.
Computer Network Sritrusta Sukaridhoto. Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
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.
Computer Networks Lecture 2 Adrian Sergiu DARABANT.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
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.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Socket Programming Lab 1 1CS Computer Networks.
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
Socket Program Training 10/29/ TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
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.
Socket Program Training 10/27/2010. What is a Socket ? An interface between an application process and transport layer (TCP or UDP). 2.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
Table Pertemuan 10 Matakuliah : L0182 / Web & Animation Design
Socket programming Péter Verhás August 2002
Pertemuan 22 The Business Views of the Technology Architecture
Introduction to Information Security
Pertemuan 11 Model TCP/IP
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Matakuliah : Web Design
Network Programming CSC- 341
Advanced Sockets Introduction to Networking
Lecture 4 Socket Programming Issues
UDP Sockets Programming
Recitation 9 Greg Reshko
Lecture 11 Overview.
TCP Sockets Programming
Advanced Network Programming spring 2007
TCP/IP Socket Programming in C
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
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:

Pertemuan 7 I/O Multiplexing Matakuliah : H0483 / Network Programming Tahun : 2008 Versi : 2.0 Pertemuan 7 I/O Multiplexing

Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mendemonstrasikan program dengan menggunakan fungsi-fungsi I/O Multiplexing

I/O Multiplexing Model Signal driven I/O Model Asynchronous I/O Model Outline Materi I/O Model Blocking I/O Model NonBlocking I/O Model I/O Multiplexing Model Signal driven I/O Model Asynchronous I/O Model Select function

Blocking I/O Model

Multiplexing I/O Model

Signal Driven

Select () The select() system call allows us to use blocking I/O on a set of descriptors (file, socket, etc). For example, we can ask select to notify us when data is available for reading on either STDIN or a TCP socket.

Select () int select( int maxfd, fd_set *readset, fd_set *writeset, fd_set *excepset, const struct timeval *timeout); maxfd : highest number assigned to a descriptor. readset : set of descriptors we want to read from. writeset : set of descriptors we want to write to. excepset : set of descriptors to watch for exceptions. timeout : maximum time select should wait

Server dgn I/O Multiplex #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #define PORT 6789

Server dgn I/O Multiplex int main(void) { fd_set master; fd_set read_fds; struct sockaddr_in myaddr; struct sockaddr_in remoteaddr; int fdmax; int listener; int newfd; int nbytes; int yes=1; int addrlen; int i,j; char buf[256]; FD_ZERO(&master); FD_ZERO(&read_fds);

Server dgn I/O Multiplex //get the listener if((listener=socket(AF_INET,SOCK_STREAM,0))==-1){ perror("socket"); exit(1); } //bind myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = INADDR_ANY; myaddr.sin_port = htons(PORT); memset(&(myaddr.sin_zero),'\0',8); if(bind(listener, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1){ perror("bind");

Server dgn I/O Multiplex if(listen(listener, 10) == -1){ perror("listen"); exit(1); } //add the listener to the master set FD_SET(listener, &master); //keep track of the biggest file descriptor fdmax=listener; //main loop for(;;){ read_fds=master; //copy it if(select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1){ perror("select"); exit(1);

Server dgn I/O Multiplex for(i=0; i<=fdmax; i++){ if(FD_ISSET(i, &read_fds)){ if(i==listener){ addrlen = sizeof(remoteaddr); if((newfd=accept(listener,(struct sockaddr*) &remoteaddr, &addrlen)) == -1){ perror("accept"); } else{ FD_SET(newfd, &master); if(newfd > fdmax) fdmax = newfd; printf("new connection from %s on socket %d\n", inet_ntoa(remoteaddr.sin_addr),newfd);

Server dgn I/O Multiplex else{ if((nbytes=recv(i,buf,sizeof(buf),0)) <= 0){ if(nbytes =0)printf("socket %d hung up\n",i); else perror("recv"); close(i); //bye FD_CLR(i,&master); } for(j=0; j<=fdmax;j++){ if(FD_ISSET(j, &master)){ if(j != listener && j != i){ if(send(j,buf,nbytes,0)==-1) perror("send");

Server dgn I/O Multiplex }//if } //for } return 0; }//main

Jelaskan perbedaan antara : Latihan Jelaskan perbedaan antara : Blocking I/O Model NonBlocking I/O Model I/O Multiplexing Model Signal driven I/O Model Asynchronous I/O Model

Latihan Dengan menggunakan contoh server diatas, buat aplikasi untuk chatting !, dengan membuat program clientnya yang cocok untuk server diatas.