serverbase.txt (1) Server Client1 (3) (2) Client2 Child Process1 Child Process2 Note: each child process keeps a separate copy of the DB.

Similar documents
CS4514 HELP Session 3. Concurrent Server (in APP) Using Go-Back-N (in DLL)

Concurrent Server Using Selective Repeat Data Link Layer

Global Employee Location Server

Εργαστήριο 9 I/O Multiplexing

CS4514 Project 2 Help Session (B07) Feng Li Nov 8, 2007

CS4514 HELP Session 2 Simulation of Datalink Layer Communication

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

ECE 650 Systems Programming & Engineering. Spring 2018

Concurrent Servers Dec 2, 2009"

call connect call read call connect ret connect call fgets Client 2 blocks waiting to complete its connection request until after lunch!

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

I/O Models. Kartik Gopalan

C08a: Data Link Protocols

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

Introduction to Client-Server Model

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

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

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

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter

CONCURRENT PROGRAMMING. Lecture 5

Experiential Learning Workshop on Basics of Socket Programming

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

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

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

Chapter 5. TCP Client-Server

Computer Networks. Data Link Layer. Design Issues. Basic Services. Notes. Paolo Costa costa. Notes. Note.

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

Client Server Computing

CS307 Operating Systems Processes

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

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

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

Socket Programming. What is a socket? Using sockets. Types (Protocols) Associated functions Styles

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Iterative Servers The course that gives CMU its Zip! Iterative servers process one request at a time. Concurrent Servers

ECE 650 Systems Programming & Engineering. Spring 2018

Three Basic Mechanisms for Creating Concurrent Flows. Systemprogrammering 2009 Föreläsning 10 Concurrent Servers. Process-Based Concurrent Server

Computer Systems Laboratory Sungkyunkwan University

Piotr Mielecki Ph. D.

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Any of the descriptors in the set {1, 4} have an exception condition pending

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

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

Concurrent Programming is Hard! Concurrent Programming. Reminder: Iterative Echo Server. The human mind tends to be sequential

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

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

CSC 1600 Unix Processes. Goals of This Lecture

CS118 Discussion 1A, Week 3. Zengwen Yuan Dodd Hall 78, Friday 10:00 11:50 a.m.

Lecture #23 Concurrent Programming

Concurrent Programming

CISC2200 Threads Spring 2015

Concurrent Programming

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

Workshop on Inter Process Communication Solutions

Semester 2, Computer Communication 352 Module 4

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Processes. Processes (cont d)

10. I/O System Library

CS3516 Computer Networks. Program 3 {October 27, 2014} 55 points

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

TCP. Networked Systems (H) Lecture 13

Inter-process communication (IPC)

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

Concurrent Programming November 28, 2007

Concurrent Programming

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

Programming with TCP/IP. Ram Dantu

Asynchronous Events on Linux

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

file:///c:/users/hpguo/dropbox/website/teaching/fall 2017/CS4470/H...

UNIT III - APPLICATION DEVELOPMENT. TCP Echo Server

CSE 489/589 Programming Assignment 2

Example Questions for Midterm EE122, Fall 2008 EECS Berkeley

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

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

Concurrent Programming

Computer Systems Assignment 2: Fork and Threads Package

ProjectDLC1: BitStuffing

Operating Systems, laboratory exercises. List 2.

Intro to LAN/WAN. Transport Layer

Operating Systems. Lecture 05

Concurrent Programming

Concurrent Programming April 21, 2005

Sliding Window Protocols, Connection Management, and TCP Reliability

Network programming(ii) Lenuta Alboaie

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

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

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S

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

Introduction to Processes

Telematics Chapter 4: Data Link Layer

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

CS4514 B08 HELP Session 1

Process Management! Goals of this Lecture!

Network Programming November 3, 2008

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations

CS240: Programming in C

Signal Example 1. Signal Example 2

Transcription:

serverbase.txt Client1 (3) (1) (2) Server Client2 Child Process1 Child Process2 Note: each child process keeps a separate copy of the DB.

Client APP Layer Server APP Layer NW Layer NW Layer DLL DLL PHL PHL TCP Connection

Clienti Read scripted action from file scripti.txt APP APP Server Read/Write a message Client Request: cmd No. [msg[ msg] nwl_send( msg ) nwl_recv( msg ) Child Process i Note: The max_size of a message is 360 bytes

Client Server message message NWL NWL Last Packet? dll_send( pkt ) dll_recv( pkt ) Note: The max_size of a packet is 50 bytes The network layer will send packets until blocked by the Data Link Layer

nwl_send( msg ) Split the msg into pkts nwl_recv( msg ) dll_recv( pkt ) Pick a pkt Last Pkt? Last Pkt? N Reassemble pkts into msg Y Add sth, \0 Forward msg to APP dll_send( pkt )

dll_send( pkt ) Split a packet into payloads Create a new frame Start a Timer Send a frame to PHL Client phl_send( ) clienti.log Force some error: 7 th frame from client 9 th frame from server Wait for receiving a ACK frame phl_recv( ) Retransmit frms if timeout or error frame!! Receive a ACK frame correctly, then continue...

Create a new frame 1. Put a payload in a frame 2. End-of-packet byte =? 3. Compute CRC struct frame { unsigned char start-flag; unsigned char seq; unsigned char crc; unsigned char data[maxsize ]; unsigned char end-of-pkt; unsigned char end-flag; 4. Byte-stuffing Note: The max_size of a frame payload is 35 bytes

dll_recv( pkt ) 7. If end-of-packet, return the packet to forward it the NWL. Server serveri.log 6. Reassemble the packet 5. Check whether it s duplicate. If yes, drop; otherwise, send ACK frame phl_send( ) Force some error 4. Drop it if there s an CRC error 3. Compute CRC and check it 2. Unstuffing the frame 1. Receive a frame from PHL phl_recv( )

clienti.log Performance Timing Packet Sent Frame received in error

More Sliding Window Protocol: Go back N Try to implement the simplest first: One-bit sliding window A single timer Then implement a sending window size of 3 or more frames How to terminate a client process: How to terminate a client process: When the client gets the response to the quit message A clean way to terminate the server child process?

Concurrent Server Example Code pid_t pid; int listenfd, connfd; listenfd = socket(... ); /* fill in sockaddr_in{ with server's well-known port */ bind (listenfd,...); listen (listenfd, LISTENQ); for(;;){ connfd = accept(listenfd,... ); /* probably blocks */ if(( pid = fork()) == 0){ close(listenfd); /* child closes listening socket */ doit(connfd); /* process the request */ close(connfd); /* done with this client */ exit(0); close(connfd); /* parent closes connected socket */

Timer Example /* example for start_timer, stop_timer, send_packet */ /* you MAY need to modify to work for project 3, this is just anexample of the TIMER,not your protocol */ #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <sys/time.h> #include <sys/timers.h> #include <sys/select.h> #include <sys/types.h> #include <errno.h> #define TIMER_RELATIVE 0 #define MAX_SEQ 3 externint errno; typedefunsigned int seq_nr; typedef enum {frame_arrival, cksum_err, timeout, network_layer_ready event_type; timer_t timer_id[max_seq]; void timeout(int x){ printf( time out!\n );

Timer Example(cont) /* you MAY need to modify to work for project 3, this is just anexample of the TIMER,not your protocol */ void start_timer(seq_nr frame_nr){ struct itimerspec time_value; signal(sigalrm, timeout); time_value.it_value.tv_sec = 1; /* timeout value */ time_value.it_value.tv_nsec = 0; time_value.it_interval.tv_sec = 0; /* timer goes off just once */ time_value.it_interval.tv_nsec = 0; timer_create(clock_realtime, NULL, &timer_id[frame_nr]); /* create timer */ timer_settime(timer_id[frame_nr], TIMER_RELATIVE, &time_value, NULL); /* set timer */ void stop_timer(seq_nr ack_expected){ timer_delete(timer_id[ack_expected]);

Timer Example(cont) /* you MAY need to modify to work for project 3, this is just anexample of the TIMER,not your protocol */ void send_packet(packet *p){ fd_set readfds; int sockfd; while(packet hasn t been finished sending){ // send frame if we can while(there s place left in sliding window) { // construct a frame from the packet; // send this frame; start timer // update sliding window size; // check data from physical layer FD_ZERO(&readfds); FD_SET(sockfd, &readfds); if(select(sockfd+1, &readfds, (fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL)<0){ if(errno == EINTR){ /* receive timeout signal */ // timeout handler, resend all frames that haven t been acknowledged continue; else{ perror("select error"); /* select error */ exit(1);

Timer Example(cont) /* you MAY need to modify to work for project 3, this is just anexample of the TIMER,not your protocol */ if(fd_isset(sockfd, &readfds)){ /* a frame come from socket */ cksum_function(); /* error check */ if(cksum error){ continue; // do nothing, wait for timer time out else{ // read the frame from socket, check to see if this frame is a data frame // or ack frame, doing corresponding processing continue;;