Part 4: Network Applications Client-server interaction, example applications.

Slides:



Advertisements
Similar presentations
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Advertisements

Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
28.2 Functionality Application Software Provides Applications supply the high-level services that user access, and determine how users perceive the capabilities.
CS335 Networking & Network Administration Tuesday, May 25, 2010.
Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write) Receive.
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
1 Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write)
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
What Is TCP/IP? The large collection of networking protocols and services called TCP/IP denotes far more than the combination of the two key protocols.
I NTRODUCTION OF S OCKET P ROGRAMMING L.Aseel AlTurki King Saud University.
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Introduction to Network Programming with Sockets Network Programming Kansas State University at Salina.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
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.
Remote Shell CS230 Project #4 Assigned : Due date :
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Distributed Computing A Programmer’s Perspective.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API)
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
UNIX Sockets Outline UNIX sockets CS 640.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
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.
Socket Programming Ameera Almasoud
Socket Abstraction and Interprocess Communication
Object-Orientated Analysis, Design and Programming
Sockets and Beginning Network Programming
Chapter 3 Internet Applications and Network Programming
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
CSI 4118 – UNIVERSITY OF OTTAWA
Client-Server Interaction
Interacting With Protocol Software
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
Issues in Client/Server Programming
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Inter-process Communication
Presentation transcript:

Part 4: Network Applications Client-server interaction, example applications

Client-Server Interaction The client-server paradigm, characteristics of clients and servers, dynamic server creation, complex client-server interactions

Application software issues Transport layer software supports the reliable transfer of data between applications Application layer software supports: – initiating connections – an application programming interface (API) – encoding data – user friendly naming – definition of specific applications

The client server paradigm A widely used form of communication Server application waits passively for contact from clients A server provides a specific service Client application actively initiates contact with the server Information can flow in both directions Typical situation is many clients interacting with each server

Characteristics of clients General application that becomes a client when remote access is needed, but that performs other computation locally Invoked by the user Executes for one session Runs on users local computer Actively initiates contact with the server Can access multiple services as needed, but only one at a time

Characteristics of servers Special purpose program to provide one service can handle multiple clients at one time invoked when the system boots runs through many sessions runs on a relatively powerful shared computer waits passively for contact from various kinds of client, but only provides one service

Transport protocols and client-server interaction Clients and servers communicate using a transport protocol - unaware of underlying layers

Server class computers Often a single server class computer runs several servers

Identifying a particular service Transport protocols assign a unique identifier to each service – server registers its ID with protocol software when it boots – client specifies the desired ID when it makes a connection TCP uses protocol port numbers

Concurrency and servers Concurrent server offers supports multiple clients at the same time Uses multiple threads of control Core part of server accepts new requests and dynamically creates new servers as separate threads to handle them Each thread deals with its client’s requests N concurrent clients => N + 1 threads TCP uses a combination of destination port and source port to identify the right thread

Complex client-server interactions A client is not restricted to accessing a single service A client does not have to use a single server for a given service A server can itself become a client of another server Watch out for circular dependencies

Distributed programming Extend client-server paradigm to more general distributed programming Provide greater transparency for programmers – remote procedure calls (RPC) – distributed objects and components Provide standard services for locating and manufacturing other services – traders – factories

Traders traderserviceclient 1. export service offer 2. Request service 3. use service

Factories traderserviceclient 1. Request service 4. use service factory 2. request create service 3. create service

Other forms of communication peer Peer to peer communication

The Socket Interface Socket API overview Socket system calls Example client and server programs

Application Programming Interface The API is the interface that the application uses to communicate with transport protocol software - usually a set of functions or classes Socket API is the de facto standard for TCP/IP Originated on UNIX but now available for other operating systems (e.g., Windows)

Sockets and descriptors Application requests the operating system to create a socket – systems returns descriptor - small integer – application then specifies details such as transport protocol, protocol addresses, specify if client or server using further functions – application then uses the descriptor as an argument to functions that “read” and “write” data – application then closes the socket

Server Client socket bind listen accept recv/send close socket connect send/recv close

Creating a socket First create a socket with descriptor = socket(protofamily,type,protocol) – protofamily specifies the protocol family to be used, e.g., PF_INET or PF_APPLETALK – type specifies the type of communication, e.g., SOCK-STREAM or SOCK_DGRAM – protocol specifies a specific protocol Function close ( socket ) terminates a socket

Binding a socket bind(socket,localaddr,addrlen) associates a socket with a protocol port number – socket is a socket descriptor – localaddr is a structure that contains a local address – addrlen specifies the length of the address

Servers and connections Server uses listen(socket,queuesize) to put a socket in passive mode. Queuesize is the length of a request queue. Server uses newsock = accept(socket, caddress, caddresslen) to accept a new connection from a client. Creates a new socket for this client and fills in the client address.

Clients and connections A client uses connect (socket, saddress, saddresslen) to connect to server – socket is the local socket for the client – saddress contains the server’s address and protocol port number – saddresslen is the length of the server’s address

Sending data send (socket, data, length, flags) – socket is a connected socket – data is a pointer to the data – length is the length of the data – flags enable debugging options sendto and sendmsg are used with connectionless communication

Receiving data recv(socket, buffer, length, flags) is used to receive data – socket is a connected socket – buffer is a pointer to allocated memory – length is the size of the buffer – flags controls additional details recvfrom and recvmsg support connectionless communication versions of the standard read and write functions are also available

Other useful functions After accepting, a server can use getpeername to get the complete address of the initiating client client or server can use gethostbyname to obtain information (e.g., IP address) about the host on which it is running gethostbyaddrr maps an IP address back to a host name

Sockets, threads and inheritance Each new thread initially inherits all existing sockets from its parent A thread typically closes sockets that it doesn’t need, removing them from its local list The system maintains a reference count for each socket- how many threads are using it - and terminates the socket when this reaches 0

Example Comer’s book (chapter 23 3 rd ed.) includes simple examples of a client and a servera client a server – server sends a message to the client saying how many times it has been contacted – server command line argument is a protocol port number – client command line arguments are a protocol port number and the name of the host on which the server is running

Networking in Java Package java.net provides the classes for implementing networking applications Using the socket classes you can implement client and server applications – ServerSocket – implements server sockets – Socket – implements client sockets – DatagramSocket – for sending and receiving datagram packets (UDP) – MulticastSocket – for sending and receiving IP multicast packets

Java Examples From the Java Developers Almanac 1.4 ( – Creating a Client Socket – Creating a Server Socket – Reading Text from a Socket – Writing Text to a Socket For further info – Java Networking Tutorial

Client import java.net.*; import java.io.*; public class Client { public static void main( String[] args) { Socket sock; InetSocketAddress address; String host = "localhost"; int port = 9101; DataInputStream is; PrintStream ps; try { // SOCKET sock = new Socket(); address = new InetSocketAddress(host, port); // CONNECT sock.connect(address); ps = new PrintStream(sock.getOutputStream());

// SEND ps.println("something or another..."); BufferedReader br = new BufferedReader ( new InputStreamReader( sock.getInputStream() ) ); // RECV String str = br.readLine(); System.out.println(str); // CLOSE sock.close(); } catch ( Exception e ) { System.err.println(e); }

Server import java.net.*; import java.io.*; public class Server { public static void main( String[] args) { ServerSocket SSock; Socket conn; InetSocketAddress address; String host = "localhost"; int port = 9101; PrintStream ps; try { // SOCKET SSock = new ServerSocket(); address = new InetSocketAddress(host, port); // BIND & LISTEN SSock.bind(address);

while (true) { // ACCEPT conn = SSock.accept(); BufferedReader br = new BufferedReader ( new InputStreamReader ( conn.getInputStream() ) ); ps = new PrintStream(conn.getOutputStream()); String str; // RECV while ( (str = br.readLine()) != null ) { System.out.println("CLIENT WROTE: " + str); // SEND ps.println("YOU WROTE: " + str); } // CLOSE conn.close(); } catch ( Exception e ) { System.err.println(e); } }}