Introduction to Client-Server Model

Similar documents
Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

UNIX Network Programming. Overview of Socket API Network Programming Basics

Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction!

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection

Randall Stewart, Cisco Systems Phill Conrad, University of Delaware

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Introduction to Socket Programming

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C.

CS321: Computer Networks Socket Programming

Piotr Mielecki Ph. D.

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

CS321: Computer Networks Introduction to Application Layer

Elementary TCP Sockets

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

socketservertcl a Tcl extension for using SCM_RIGHTS By Shannon Noe - FlightAware

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups)

Semester 2, Computer Communication 352 Module 4

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services.

CS 3516: Computer Networks

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

Programming with TCP/IP. Ram Dantu

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

Oral. Total. Dated Sign (2) (5) (3) (2)

Experiential Learning Workshop on Basics of Socket Programming

Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class. Not submitted. Not scored

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1

Distributed Systems. 02. Networking. Paul Krzyzanowski. Rutgers University. Fall 2017

Network Programming November 3, 2008

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

CS 640: Computer Networking

/* * porting from BSD to SVR4 */ #ifdef USE_BSD # include <machine/param.h> #endif

ECE 435 Network Engineering Lecture 2

Data and Computer Communications. Tenth Edition by William Stallings

Tutorial on Socket Programming

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

Sockets 15H2. Inshik Song

ECE 650 Systems Programming & Engineering. Spring 2018

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

Transport Layer. The transport layer is responsible for the delivery of a message from one process to another. RSManiaol

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

Socket Programming for TCP and UDP

The User Datagram Protocol

ECE 435 Network Engineering Lecture 2

CSE 333 Lecture 16 - network programming intro

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

Applications and Layered Architectures. Chapter 2 Communication Networks Leon-Garcia, Widjaja

UDP CONNECT TO A SERVER

The Client Server Model and Software Design

Socket Programming TCP UDP

Computer Systems Laboratory Sungkyunkwan University

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

Group-A Assignment No. 6

CPSC 213. Introduction to Computer Systems. Inter-Process Communication. Unit 2f

Computer Network Lab, SS Fachgebiet Technische Informatik, Joachim Zumbrägel. Overview. Sockets. Sockets in C.

04 Elementary. Client/Server. CEN 463 Network Programming. Dr. Mostafa Hassan Dahshan. King Saud University

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming

Client Server Computing

CSE 333 SECTION 8. Sockets, Network Programming

Concurrent Programming

A GENERALIZED FRAMEWORK FOR CATV TRANSMISSION ON FUTURE BISDN

Network Communication

Outline. Distributed Computer Systems. Socket Basics An end-point for a IP network connection. Ports. Sockets and the OS. Transport Layer.

Network Socket Programming - 3 BUPT/QMUL

Unix Network Programming

Department of Computer Science

Chapter 6. The Transport Layer. Transport Layer 3-1

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

System Programming. Sockets

Network Socket Programming - 3 BUPT/QMUL

A REPORT ON DNS Client Application

Socket Programming 2007/03/28

System Programming. Sockets: examples

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

UNIT IV- SOCKETS Part A

Total Score is updated. The score of PA4 will be changed! Please check it. Will be changed

UNIT IV - SOCKET OPTIONS, ELEMENTARY UDP SOCKETS

CSE 333 Lecture network programming intro

Concurrent Programming. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

How do we Communicate? Introduction to Unix Network Programming. What does Alice do? What does Bob do? Two simplest networking programs

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

Sockets and Parallel Computing. CS439: Principles of Computer Systems April 11, 2018

Network programming(i) Lenuta Alboaie

CSE 333 SECTION 7. Client-Side Network Programming

Chapter 23 Process-to-Process Delivery: UDP, TCP, and SCTP 23.1

Lecture 20 Overview. Last Lecture. This Lecture. Next Lecture. Transport Control Protocol (1) Transport Control Protocol (2) Source: chapters 23, 24

CSE/EE 461 Lecture 14. Connections. Last Time. This Time. We began on the Transport layer. Focus How do we send information reliably?

CS 471 Operating Systems. Spring 2016 Midterm Exam Time 2 & 1/2 hours. Open Book & Notes

Lab 0. Yvan Petillot. Networks - Lab 0 1

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

Transcription:

Preview Introduction to Client-Server Model Motivation of Client-Server Model Terminologies and Concepts in Client-Server Model Connectionless vs. Connection-Oriented Stateless vs. Stateful Server Identify a client by Stateful Server Server as a Client COSC350, System Software, Fall 2015 1

Motivation of Client-Server Model The fundamental motivation for the client-server paradigm arises from the problem rendezvous. A sender will send a message when it is ready to send. But receiver does not know when sender send a message to the receiver. The client-server model solves the rendezvous problem in a straightforward way. In any pair of communicating applications, one side must start execution and wait (indefinitely) for the other side to contact it. COSC350, System Software, Fall 2015 2

Terminologies in Client-Server Model Client an application that initiates peerto peer communication. Each time client executes, it contacts a server, send a request, and awaits a response. Server any program that waits for incoming communication requests from a client. The server receives a client s request, performs the necessary computation, and returns the result to the client. COSC350, System Software, Fall 2015 3

Terminologies in Client-Server Model A server contains code that handles many issues that can be grouped under security: Authentication verifying the identity of the client Authorization check the permission for the client to access the service Data security guarantee that data is not unintentionally revealed Privacy keep information from unauthorized access Protection guarantee that network application cannot abuse system resource COSC350, System Software, Fall 2015 4

Connectionless vs. Connection-Oriented When programmer designs client-server application software, they must choose types of interaction. Connectionless use User Datagram Protocol (UDP) Connection-Oriented use Transmission Control Protocol (TCP) or use Stream Control Transmission Protocol (SCTP) COSC350, System Software, Fall 2015 5

Connectionless vs. Connection-Oriented Are you getting all of this? Who Cares? Just Send it faster UDP: Connectionless COSC350, System Software, Fall 2015 6

Connectionless vs. Connection-Oriented Are you getting all of this? OK! I am sending again I got it! Can you send again? Slow down! TCP: Connection- Oriented COSC350, System Software, Fall 2015 7

Connectionless vs. Connection-Oriented TCP provide full reliability by taking care of all transmission problems: Verifies data arrives- if not, retransmit segment. Error checking by checking checksum, guarantee error free transmission. TCP uses sequence number to ensure the data arrives in order and eliminate duplicate copy. TCP provides flow control to ensure that the sender does not transmit data faster than receiver can consume it. COSC350, System Software, Fall 2015 8

Connectionless vs. Connection-Oriented UDP do not have any guarantees about reliable delivery When a client sends a request, the request may be lost, duplicated, delayed or delivered out of order. A response from the server to client also might be lost, duplicated, delayed or delivered out of order. If a programmer use UDP for client-server application, application software itself must contain code to take care of such errors. COSC350, System Software, Fall 2015 9

Connectionless vs. Connection-Oriented Program only use UDP if the application Protocol handles reliability, application requires hardware broadcast or multicast, or the overhead for reliability is not needed. UDP is commonly used for streaming audio and video. Streaming media such as Windows Media audio files (.WMA), Real Player (.RM), and others use UDP because it offers speed! The reason UDP is faster than TCP is because there is no form of flow control or error correction. COSC350, System Software, Fall 2015 10

Stateless Vs. Stateful Server A stateless server is a server that treats each request as an independent transaction that is unrelated to any previous request. The motivation of a stateless server lies in protocol reliability. State information in a server can become incorrect if messages are lost, duplicated, or delivered out of order. It cause server might respond incorrectly. COSC350, System Software, Fall 2015 11

Stateless Vs. Stateful Server Ex) Stateless file server Since server does not save any information regarding a client request, each request from a client must specify complete information: operation (read/write), name of file, position in the file, number of bytes to transfer, and data (for writing). COSC350, System Software, Fall 2015 12

Stateless Vs. Stateful Server A stateful server is a server which keeps data about previous requests for a service which can then be used for subsequent requests. Keeping a small amount of information can reduce the size of messages that the client and server exchange, and can allow the server to respond to requests quickly. If the client state change by error (ex. Client site support multiple IP, Client site change IP address), stateful server might send wrong response. COSC350, System Software, Fall 2015 13

Stateless Vs. Stateful Server Ex Stateful file server) A stateful file server maintains a table that holds information about each client and the file currently being accessed. Once a client begins accessing a file (read or write), the server retain information: operation, name of file, and position in the file. After initial request to read from a file, subsequent read request messages only need to contain one field: the number of bytes to read. Once client begins writing data, each subsequent write request messages only need to contain two fields: the number of bytes to write and data. COSC350, System Software, Fall 2015 14

Stateless Vs. Stateful Server Ex Stateful file server Cont.) Consider what will happen if the network duplicates a read request from a client to sateful file server. Server updates its notion of file position each time the client extract data from a file. Server will receive two copies of request since the read request is duplicated. When the first copy arrives, server extracts data from the file, updates the file position and returns the result to client. When the second copy arrives, server extracts data again from the file, updates the file position again and returns the result to the client. Client will receive two different results for one request. Client might discard it or it may reports an error since it received two different results for one request. COSC350, System Software, Fall 2015 15

Stateless Vs. Stateful Server Client A client request read a file to a file server Send read request with client s full information Return a result + a handle to the Client Stateful file Server Create an entry in the state table for the client and save information. Create a handle for the client A client receive two data for one request. Send subsequent requests with the handle. This request is duplicated in the network. Return a result to the Client Return a result to the Client Server receive the first copy of duplicated request. Server extracts data from the file, updates the file position Server receive the second copy of duplicated request. Server extracts data from the file, updates the file position COSC350, System Software, Fall 2015 16

Identify a Client by Stateful Server Two general approaches to identify clients: Endpoint, Handle Endpoints The sever ask the underlying transport protocol to provide identifying information when a request arrives (IP address and Port number used by client). Then, the server uses the endpoint information to identify a particular slot in its state table. Unfortunately, endpoint information can change (ex. A client need to open a new TCP connection due to a network failure). COSC350, System Software, Fall 2015 17

Identify a Client by Stateful Server Two general approaches to identify clients: Endpoint, Handle Handle When the client first sends a request, the client must specify complete information. The server allocates an entry in its state table, and generates a short identifier for the entry called handle which is small integer value. The sever send the handle to the client for use in subsequent request. COSC350, System Software, Fall 2015 18

Identify a Client by Stateful Server Client send request with client s full information Server Send the handle to Client Create an entry in the state table for the client and save information. Create a handle for the client Send subsequent requests with the handle COSC350, System Software, Fall 2015 19

Server as a Client Internet Time Server File Server A Client COSC350, System Software, Fall 2015 20

Server as a Client Programs do not always fit exactly into the definition of client or server. A server can be a client of other server. For example, a file server is currently running on a system without time-of-day clock. Server need to obtain the time of day so it can stamp files with the time of access. The server can get the time of day information from time server. COSC350, System Software, Fall 2015 21

Client/Server Program #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <netdb.h> #include <time.h> #define SA struct sockaddr /* generic socket address */ #define LISTENQ 1024 /* 2nd argument to listen() */ #define MAXLINE 4096 /* max text line length */ COSC 350 System Software, Fall2015 22

int main() { int len, listenfd, connfd; /* for server and client address */ struct sockaddr_in servaddr, cliaddr; char buff[maxline]; /* for sending message to client */ time_t CurrTime; /*create a socket for server using IPv4 with TCP */ listenfd = socket(af_inet, SOCK_STREAM, 0); /*clear struct sokaddr_in for server */ bzero(&servaddr, sizeof(servaddr)); /* use IPv4 */ servaddr.sin_family = AF_INET; /* allow clients to connect using any one of the host's IP addresses */ servaddr.sin_addr.s_addr = htonl(inaddr_any); /* set daytime server port as 1313. htons function format port number to short*/ servaddr.sin_port = htons(1313); } /* bind a space for client request */ bind(listenfd, (SA *) &servaddr, sizeof(servaddr)); /* waiting for client request */ listen(listenfd, LISTENQ); /* seqential server need queue */ while(1) { /* make a space for client address */ len = sizeof(cliaddr); /* accept connection from a client */ connfd = accept(listenfd, (SA *) &cliaddr, &len); /* issue current time as Unix time */ CurrTime = time(null); /* convert Unix time to formated output and a save in buffer */ snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&currtime)); /* send message to client */ write(connfd, buff, strlen(buff)); close(connfd); } COSC 350 System Software, Fall2015 23

void err_sys(char *); int main(int argc, char **argv) { int sockfd, n; /*socket file descriptor */ char recvline[maxline + 1]; struct sockaddr_in servaddr;/*server address */ if (argc!= 2) err_sys("argument error"); /*create a socket to receive data from server */ if ( (sockfd = socket(af_inet, SOCK_STREAM, 0)) < 0) err_sys("socket error"); /* shall place n zero-valued bytes in the area pointed to by serveraddr */ bzero(&servaddr, sizeof(servaddr)); /* server using IPv4 */ servaddr.sin_family = AF_INET; /* port number used by server. htons function format port number to short*/ servaddr.sin_port = htons(1313); /* converts the character string argv[i] into a network address structure /* in the IPv4 address family, then copies to servaddr.sin_addr. */ if (inet_pton(af_inet, argv[1], &servaddr.sin_addr) <= 0) err_sys("inet_pton error"); /*try to connect to server */ if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) err_sys("connect error"); /* receive information from the daytime server*/ while ( (n = read(sockfd, recvline, MAXLINE)) > 0) { recvline[n] = 0; /* null terminate */ if (fputs(recvline, stdout) == EOF) err_sys("fputs error"); } if (n < 0) err_sys("read error"); exit(0); } void err_sys(char *str) { printf ("%s \n",str); exit (1); } COSC 350 System Software, Fall2015 24

client server socket() bind() listen() socket() connect() Connection established by TCP three-way handshake accept() No Read() write() Ye Read() s Welcome message + ask for game Yes or No write() read() Shuffle Card Display Five Card write() Send second chance cards info write() read() Read() What is on hand Display Final five cards + what is on hand write() close() close() COSC 350 System Software, Fall2015 25