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.

Slides:



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

Socket Programming 101 Vivek Ramachandran.
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Socket Programming CS3320 Fall 2010.
Socket Programming. Basics Socket is an interface between application and network – Application creates a socket – Socket type dictates the style of communication.
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.
Socket Programming.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
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.
EECS122 Communications Networks Socket Programming January 30th, 2003 Jörn Altmann.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
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:
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Winsock programming.  TCP/IP UDP TCP  Winsock #include wsock32.lib.
Introduction to Project 1 Web Client and Server Jan 2006.
Sockets COS 518: Advanced Computer Systems Michael Freedman Fall
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.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
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.
 Wind River Systems, Inc Chapter - 13 Network Programming.
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.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network 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.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Remote Shell CS230 Project #4 Assigned : Due date :
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 Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
Introduction to Socket
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Socket Programming Lab 1 1CS Computer Networks.
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,
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
回到第一頁 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.
©The McGraw-Hill Companies, Inc., 2000© Adapted for use at JMU by Mohamed Aboutabl, 2003Mohamed Aboutabl1 1 Chapter 16 Socket Interface.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
EECS340 Recitation 1: Very helpful to your project Hongyu Gao 1.
1 Network Communications A Brief Introduction. 2 Network Communications.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
UNIX Sockets COS 461 Precept 1.
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Tutorial on Socket Programming
Advanced Sockets Introduction to Networking
Lecture 4 Socket Programming Issues
Socket Programming.
Issues in Client/Server Programming
Presentation transcript:

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 Ng, Ion Stoica, Hui Zhang T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

2 Example of Iterated DNS Query Root name server: May not know authoritative name server May know intermediate name server: who to contact to find authoritative name server Iterated query: Contacted server replies with name/address of another server “I don’t know this name, but ask this server” wants to lookup root name server local name server moe.rice.edu authoritative name server ns1.google.com 6 7 intermediate name server (com server) 5 8

How to Programmatically Use the DNS System? On Linux: gethostbyname() gethostbyaddr() T. S. Eugene Ng eugeneng at cs.rice.edu Rice University3

How to Programmatically Send/Receive Data over the Internet? T. S. Eugene Ng eugeneng at cs.rice.edu Rice University4

Agenda Reliable byte stream network communications –The most common model –Gives you the right mental model of what’s going on –Helps understand byte ordering confusions 5T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Reliable Byte Stream Model Bytes are delivered reliably, first in first out 6 bytes sent bytes received 0x120xf20x3aNetwork Abstraction T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Reliable Byte Stream Bytes are delivered without any notion of application message units 7 0x120xf20x3a 1st recv() got 0x12 2nd recv() got 0xf2, 0x3a Example 1 1st recv() got nothing due to timeout 2nd recv() got 0x12, 0xf2 3rd recv() got 0x3a 0x120xf20x3a Example 2 T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Application Decides the Message Format Message format is an important part of a “protocol” E.g. IP version 4 8 *Bytes transmitted row by row, from left to right bit # SIZE of message!!! T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Another Example Message Format Each message is a null (0x00) terminated string In this case, a program reads in bytes until encountering 0x00 to form a valid message 9T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Project 1 Ping/Pong Message 10 sizetv_sec tv_usec additional optional data x120xf2 2 size bytes What is the size? 0x12f2 = 4,850 0xf212 = 61,970 Network byte order (a.k.a. Big endian) – first byte is the most significant size is 0x12f2 = 4,850 T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Byte ordering conversion functions Most Intel CPUs are “little-endian” (1 st byte least significant) –Network byte ordering convention is “big-endian” (1 st byte most significant) host order to network order –htons() for short integer (i.e. 16 bit) –htonl() for long integer (i.e. 32 bit) –htobe64() for 64 bit network order to host order –ntohs() –ntohl() –be64toh() Must be very careful in deciding whether conversion is required These functions are “no-op” on CPUs that use network byte ordering (big-endian) for internal number representation –But a program must work regardless of CPU, so these functions have to be used for compatibility 11T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

How to Programmatically Send/Receive Data over the Internet? T. S. Eugene Ng eugeneng at cs.rice.edu Rice University12

Agenda Socket API –Refresh your memory of the mechanics of using socket for network communications 13T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

Overview of the Socket API 14 Client Server socket bind listen accept close connect close Connection request send, recv T. S. Eugene Ng eugeneng at cs.rice.edu Rice University create a file descriptor associate with address and port number a new descriptor is created for this connection

How to Programmatically Send/Receive Data over the Internet? T. S. Eugene Ng eugeneng at cs.rice.edu Rice University15

Agenda Event-driven concurrency –Refresh your memory of one way to create the illusion of concurrently handling multiple network conversations even on a uni-processor –Another way is multi-threading Can achieve real concurrency on multi-processors Refer to COMP221 material 16T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

17 Event-Based Concurrent Servers I/O multiplexing Maintain a pool of descriptors Repeat the following forever: –Use the Unix select() function to block until: New connection request arrives on the listening descriptor New data arrives on an existing connected descriptor A connected descriptor is ready to be written to A timeout occurs (can be configured to have no timeout) –If new connection request, add the new connection to the pool of connections –If new data arrives, read any available data from the connection –If descriptor is ready to be written, write whatever data is pending –If timeout, do whatever is appropriate for timeout Can wait for input from local I/O (standard input) and remote I/O (socket) simultaneously! T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

18 Event-Based Concurrent I/O readfds, writefds –Opaque bit vector (max FD_SETSIZE bits) that indicates membership in a descriptor set –If bit k is 1, then descriptor k is a member of the descriptor set nfds – Maximum descriptor value + 1 in the set – Tests descriptors 0, 1, 2,..., nfds - 1 for set membership select () returns the number of ready descriptors and sets each bit of readfds, writefds to indicate the ready status of its corresponding descriptor int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); T. S. Eugene Ng eugeneng at cs.rice.edu Rice University

19 Macros for Manipulating Set Descriptors void FD_ZERO(fd_set *fdset); –Turn off all bits in fdset void FD_SET(int fd, fd_set *fdset); –Turn on bit fd in fdset void FD_CLR(int fd, fd_set *fdset); –Turn off bit fd in fdset int FD_ISSET(int fd, *fdset); –Is bit fd in fdset turned on? T. S. Eugene Ng eugeneng at cs.rice.edu Rice University