 Wind River Systems, Inc. 1997 Chapter - 13 Network Programming.

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.
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.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
1 Netcomm Recitation 1: Sockets Communication Networks Recitation 1.
Socket Programming.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
SOCKETS Lecture #3. The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in Developed at UC Berkeley Objective: to transport.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
ECE 4110 – Internetwork Programming Client-Server Model.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Zhu Reference: Daniel Spangenberger Computer Networks, Fall 2007 PPT-4 Socket Programming.
Sirak Kaewjamnong Computer Network Systems
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.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
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
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API)
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
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 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
SOCKET PROGRAMMING Presented By : Divya Sharma.
UNIX Sockets COS 461 Precept 1.
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Tutorial on Socket Programming
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
Socket Programming in C
TCP Sockets Programming
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Presentation transcript:

 Wind River Systems, Inc Chapter - 13 Network Programming

13-2 Network Programming 13.1 Introduction Sockets UDP Sockets Programming TCP Sockets Programming RPC

13-3 VxWorks Networking  Network programming allows users to:  Build services.  Create distributed applications.  VxWorks network programming tools:  Berkeley sockets.  zbuf Socket API.  Sun RPC (Remote Procedure Call).

13-4 Network Components

13-5 Network Components

13-6 Network Components

13-7 Ports  Abstract destination point within a node.  TCP/UDP intertask communication:  Data is sent by writing to a remote port.  Data is received by reading from a local port.

13-8 Network Components

13-9 Network Components

13-10 Packet Encapsulation

13-11 Network Programming Introduction 13.2 Sockets UDP Sockets Programming TCP Sockets Programming RPC

13-12 Socket Overview  Programmatic interface to internet protocols.  Protocol specified when socket created (e.g., UDP or TCP).  Server binds its socket to a well known port.  Client’s port number dynamically assigned by the system.

13-13 Ports  Socket address consists of:  An internet address (node socket is on).  A port number (destination within that node).  Port identified by a short integer. VxWorks port usage conventions: Reserved for system services (e.g., rlogin, telnet, etc.) Dynamically allocated. > 5000 User defined.  Unique to each machine and protocol.

13-14 Socket Address  Generic socket address: struct sockaddr { u_short sa_family; /* address family */ char sa_data[14];/* protocol specific address data */ };  Socket address structure used by Internet Protocol: struct sockaddr_in { short sin_family; /* AF_INET */ u_short sin_port; /* port number */ struct in_addr sin_addr; /* internet address */ char sin_zero[8];/* padding, must be zeroed out */ }; VxWorks supports only Internet sockets.

13-15 Network Byte Ordering  Fields in the struct sockaddr_in must be put in network byte order (big-endian).  Macros to convert long/short integers between the host and the network byte ordering: htonl( ) host to network long. htons( ) host to network short. ntohl( ) network to host long. ntohs( ) network to host short.

13-16 Caveat - User Data  To send data in a system independent way: 1. Sender converts data from its system-dependent format to some standard format. 2. Receiver converts data from the standard format to its system- dependent format.  The standard format used must handle:  Any standard data types used (e.g., int, short, float, etc.).  Data structure alignment.  One such facility, XDR, will be discussed in the RPC section of this chapter.

13-17 Creating a Socket int socket (domain, type, protocol) domain Must be PF_INET. type Typically SOCK_DGRAM (UDP) or SOCK_STREAM (TCP). protocol Socket protocol (typically 0).  Opens a socket (analogous to open( ) for files).  Returns a socket file descriptor or ERROR.

13-18 Binding a Socket  To bind a socket to a well known address: STATUS bind (sockFd, pAdrs, adrsLen) sockFd Socket descriptor returned from socket( ). pAdrs Pointer to a struct sockaddr to which to bind this socket. adrsLen sizeof (struct sockaddr).  Typically only called by server.

13-19 Example Server Stub 1 #define PORT_NUM (USHORT)5001; 2 struct sockaddr_in myAddr; 3 int mySocket; mySocket = socket (PF_INET, SOCK_DGRAM,0); 6 if (mySocket == ERROR) 7 return (ERROR); 8 9 bzero (&myAddr, sizeof (struct sockaddr_in)); 10 myAddr.sin_family = AF_INET; 11 myAddr.sin_port = htons (PORT_NUM); 12 myAddr.sin_addr.s_addr = INADDR_ANY; if (bind (mySocket, (struct sockaddr *)&myAddr, 15 sizeof (myAddr)) == ERROR) 16 { 17 close (mySocket); 18 return (ERROR); 19 }

13-20 Network Programming Introduction Sockets 13.3 UDP Sockets Programming TCP Sockets Programming RPC

13-21 UDP Socket Overview

13-22 Sending Data on UDP Sockets int sendto (sockFd, pBuf, bufLen, flags, pDestAdrs, destLen) sockFd Socket to send data from. pBuf Address of data to send. bufLen Length of data in bytes. flags Special actions to be taken. pDestAdrs Pointer to struct sockaddr containing destination address. destLen sizeof (struct sockaddr).  Returns the number of bytes sent or ERROR.

13-23 Receiving Data on UDP Sockets int recvfrom (sockFd, pBuf, buflen, flags, pFromAdrs, pFromLen) sockFd Socket to receive data from. pBuf Buffer to hold incoming data. buflen Maximum number of bytes to read. flags Flags for special handling of data. pFromAdrs Pointer to struct sockaddr. Routine supplies internet address of sender. pFromLen Pointer to integer. Must be initialized to sizeof (struct sockaddr).  Blocks until data available to receive.  Returns number of bytes received or

13-24 Network Programming Introduction Sockets UDP Sockets Programming 13.4 TCP Sockets Programming RPC

13-25 TCP Socket Overview  TCP is connection based (like making a phone call).  Concurrent servers are often implemented:

13-26 TCP Server Overview 1 /* master server */ 2 masterFd = socket (PF_INET, SOCK_STREAM, 0) 3 /* fill in server’s sockaddr struct */ 4 bind (...) /* bind to well-known port */ 5 listen (...) /* configure request queue */ 6 FOREVER 7 { 8 clientFd = accept (masterFd,...) 9 taskSpawn (..., slaveSrv, clientFd,...) 10 } 1 /* slave server */ 2 slaveSrv(clientFd,...) 3 { 4 read (clientFd,...) /* read request */ 5 serviceClient () 6 write (clientFd,...) /* send reply */ 7 close (clientFd) 8 }

13-27 TCP Client Overview 1/* TCP Client */ 2 fd = socket (PF_INET, SOCK_STREAM, 0) 3 4 /* fill in sockaddr with server’s address */ 5 6 connect (fd,...) /* request service */ 7 8 write (fd,...) /* send request */ 9 read (fd,...) /* read reply */ close (fd) /* terminate connection */

13-28 Server Initialization  Before accepting connections, server must:  Create a socket (socket( )).  Bind the socket to a well known address (bind( )).  Establish a connection request queue: STATUS listen (sockFd, queueLen) sockFd Socket descriptor returned from socket( ). queueLen Nominal length of connection request queue.

13-29 Accepting Connections int accept (sockFd, pAdrs, pAdrsLen) sockFd Servers socket (returned from socket( )). pAdrs Pointer to a struct sockaddr through which the client’s address is returned. pAdrsLen Pointer to length of address.  Blocks until connection request occurs.  Returns new socket file descriptor (connected to the client) or ERROR.  Original socket, sockFd, is unconnected and ready to accept other connection requests.

13-30 Requesting Connections  To connect to the server, the client calls: STATUS connect (sockFd, pAdrs, adrsLen) sockFd Client’s socket descriptor. pAdrs Pointer to server’s socket address. adrsLen sizeof (struct sockaddr)  Blocks until connection is established or timeout.  Returns ERROR on timeout or if no server is bound to pAdrs.

13-31 Exchanging Data  read( )/write( ) may be used to exchange data:  Caveat: TCP is stream oriented.  write( ) may write only part of message if I/O is nonblocking.  read( ) may read more or less than one message.

13-32 Cleaning up a Stream Socket  When done using a socket, close( ) it:  Frees resources associated with socket.  Attempts to deliver any remaining data.  Causes read( ) from peer socket to return 0.  Can also use shutdown( ) to terminate output, while still receiving data from peer

13-33 Setting Socket Options  Options can be enabled on a per socket basis, including:  Don’t delay write( )’s to coalesce small TCP packets.  Enable UDP broadcasts.  Linger on close( ) until data is sent.  bind( ) to an address already in use.  Change the size of the send/receive buffers.  Consult UNIX man pages on setsockopt( ) for details.  To make a socket non-blocking: int val = 1; /* Set to 0 for blocking I/O */ ioctl (sock, FIONBIO, &val);

13-34 zbuf Socket API  Improves application performance by minimizing data copies through buffer loaning.  Application must manage buffers.  zbuf application can communicate with a standard socket application.  Supports TCP and UDP protocols.  See zbufLib and zbufSockLib for details.  Proprietary API.

13-35 Network Programming Introduction Sockets UDP Sockets Programming TCP Sockets Programming 13.5 RPC

13-36 Overview  RPC (Remote Procedure Call) provides a standard way to invoke procedures on a remote machine.  For more information about RPC, see:  Appendix.  TCP/IP Illustrated Volume I (Stevens).  Power Programming with RPC (O’Reilly & Associates).  Documentation and source code can be found in wind/target/unsupported/rpc4.0

13-37 RPC Client - Server Model

13-38 VxWorks and rpcgen  rpcgen is a RPC protocol compiler.  From a specification of the remote procedures, rpcgen creates:  A client stub.  A server stub.  The XDR routines for packing/unpacking data structures. Not created if all parameters/return values are standard data types.  A header file for inclusion by client and server.  Each VxWorks task accessing RPC calls using code produced by rpcgen must first initialize access. STATUS rpcTaskInit( )

13-39 Summary  Transport layer network Protocols: TCP Stream-oriented, reliable port-to-port communication. UDP Packet-oriented, non-reliable port-to- port communication.  Sockets as the interface to network protocols:  UDP transport protocol  TCP transport protocol  Configurable socket options  zbuf socket API.  Client/server programming strategies for distributed applications.