Lecture 17 Client/Server Programming Chat CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.

Slides:



Advertisements
Similar presentations
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Advertisements

Remote Procedure Call (RPC)
CCNA – Network Fundamentals
Intermediate TCP/IP TCP Operation.
1 Chapter 6 Datagram Delivery by UDP Just as the Internet Protocol uses the services of subnetworks, transport protocols build upon the services of IP.
Data Communications and Networking (Third Edition)
Slide 1 Client / Server Paradigm. Slide 2 Outline: Client / Server Paradigm Client / Server Model of Interaction Server Design Issues C/ S Points of Interaction.
Lecture 16 Overview. Creating a TCP socket int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen); int mysock; struct sockaddr_in myaddr;
Socket Programming.
Introduction to Network Programming and Client-Server Design.
Chapter 23: ARP, ICMP, DHCP IS333 Spring 2015.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
Gursharan Singh Tatla Transport Layer 16-May
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
Process-to-Process Delivery:
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
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.
© 2008 Cisco Systems, Inc. All rights reserved.Cisco ConfidentialPresentation_ID 1 Chapter 7: Transport Layer Introduction to Networking.
 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.
1 Version 3.0 Module 11 TCP Application and Transport.
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.
CS332, Ch. 26: TCP Victor Norman Calvin College 1.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
Lecture 3 Overview. Protocol An agreed upon convention for communication both endpoints need to understand the protocol. Protocols must be formally defined.
Copyright © Curt Hill, Client – Server Computing An important paradigm.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Application Layer Khondaker Abdullah-Al-Mamun Lecturer, CSE Instructor, CNAP AUST.
Chapter 2 Applications and Layered Architectures Sockets.
1 Server Design Discuss Design issues for Servers Review Server Creation in Windows.
The InetAddress Class A class for storing and managing internet addresses (both as IP numbers and as names). The are no constructors but “class factory”
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
TCP/IP (Transmission Control Protocol / Internet Protocol)
Networking Basics CCNA 1 Chapter 11.
Lecture 4 Overview. Ethernet Data Link Layer protocol Ethernet (IEEE 802.3) is widely used Supported by a variety of physical layer implementations Multi-access.
1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Dynamic Host Configuration Protocol (DHCP)
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Client/Server Socket Programming Project
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Socket Programming.
WEEK 11 – TOPOLOGIES, TCP/IP, SHARING & SECURITY IT1001- Personal Computer Hardware System & Operations.
1 Tips for the assignment. 2 Socket: a door between application process and end- end-transport protocol (UDP or TCP) TCP service: reliable transfer of.
4343 X2 – The Transport Layer Tanenbaum Ch.6.
Netprog: Chat1 Chat Issues and Ideas for Service Design Refs: RFC 1459 (IRC)
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
1 Kyung Hee University Chapter 11 User Datagram Protocol.
Data Communications and Networks Chapter 6 – IP, UDP and TCP ICT-BVF8.1- Data Communications and Network Trainer: Dr. Abbes Sebihi.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
1 Network Communications A Brief Introduction. 2 Network Communications.
R Some of these slides are from Prof Frank Lin SJSU. r Minor modifications are made. 1.
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
Process-to-Process Delivery:
IST 201 Chapter 11 Lecture 2. Ports Used by TCP & UDP Keep track of different types of transmissions crossing the network simultaneously. Combination.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
Chapter 11 User Datagram Protocol
The Transport Layer Implementation Services Functions Protocols
Boots Cassel Villanova University
File Transfer and access
NET323 D: Network Protocols
Client-Server Interaction
Subject Name: Computer Communication Networks Subject Code: 10EC71
Chat Refs: RFC 1459 (IRC).
Lecture 4 Socket Programming Issues
NET323 D: Network Protocols
Process-to-Process Delivery:
Issues in Client/Server Programming
Internet Applications & Programming
Process-to-Process Delivery: UDP, TCP
Presentation transcript:

Lecture 17 Client/Server Programming Chat CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger

Issues in Client/Server Programming  Identifying the Server.  Looking up an IP address.  Looking up a well known port name.  Specifying a local IP address.  UDP/TCP client design. Client/Server Issues 2

Identifying the Server  Options:  hard-coded into the client program.  require that the user identify the server.  read from a configuration file.  use a separate protocol/network service to lookup the identity of the server. Client/Server Issues 3

Identifying a TCP/IP server  Need an IP address, protocol and port.  We often use host names instead of IP addresses  usually the protocol is not specified by the user UDP vs. TCP  often the port is not specified by the user. Client/Server Issues 4

Services and Ports  Many services are available via “well known” addresses (names).  There is a mapping of service names to port numbers: struct *servent getservbyname( char *service, char *protocol );  servent->s_port is the port number in network byte order. Client/Server Issues 5

Specifying a Local Address  When a client creates and binds a socket, it must specify a local port and IP address  Typically a client doesn’t care what port it is on: haddr->port = htons(0); Client/Server Issues 6 give me any available port !

Local IP address A client can also ask the operating system to take care of specifying the local IP address: haddr->sin_addr.s_addr= htonl(INADDR_ANY); Client/Server Issues 7 Give me the appropriate address

UDP Client Design  Establish server address (IP and port).  Allocate a socket.  Specify that any valid local port and IP address can be used.  Communicate with server (send, recv)  Close the socket. Client/Server Issues 8

Connected mode UDP  A UDP client can call connect() to establish the address of the server  The UDP client can then use read() and write() or send() and recv()  A UDP client using a connected mode socket can only talk to one server  using the connected-mode socket Client/Server Issues 9

TCP Client Design  Establish server address (IP and port).  Allocate a socket.  Specify that any valid local port and IP address can be used.  Call connect()  Communicate with server (read, write).  Close the connection. Client/Server Issues 10

Closing a TCP socket  Many TCP based application protocols support  multiple requests and/or  variable length requests over a single TCP connection.  How does the server known when the client is done ?  and it is OK to close the socket ? Client/Server Issues 11

Partial Close  One solution is for the client to shut down only it’s writing end of the socket.  The shutdown() system call provides this function. shutdown(int s, int direction);  direction can be 0 to close the reading end or 1 to close the writing end.  shutdown sends info to the other process! Client/Server Issues 12

TCP sockets programming  Common problem areas:  null termination of strings.  reads don’t correspond to writes.  synchronization (including close()).  ambiguous protocol. Client/Server Issues 13

TCP Reads  Each call to read() on a TCP socket returns any available data  up to a maximum  TCP buffers data at both ends of the connection.  You must be prepared to accept data 1 byte at a time from a TCP socket! Client/Server Issues 14

Server Design Client/Server Issues 15 Iterative Connectionless Iterative Connectionless Iterative Connection-Oriented Iterative Connection-Oriented Concurrent Connection-Oriented Concurrent Connection-Oriented Concurrent Connectionless Concurrent Connectionless

Concurrent vs. Iterative Client/Server Issues 16 Iterative Small, fixed size requests Easy to program Iterative Small, fixed size requests Easy to program Concurrent Large or variable size requests Harder to program Typically uses more system resources Concurrent Large or variable size requests Harder to program Typically uses more system resources

Connectionless vs. Connection-Oriented Client/Server Issues 17 Connection-Oriented EASY TO PROGRAM transport protocol handles the tough stuff. requires separate socket for each connection. Connection-Oriented EASY TO PROGRAM transport protocol handles the tough stuff. requires separate socket for each connection. Connectionless less overhead no limitation on number of clients Connectionless less overhead no limitation on number of clients

Statelessness  State: Information that a server maintains about the status of ongoing client interactions.  Connectionless servers that keep state information must be designed carefully! Client/Server Issues 18 Messages can be duplicated!

The Dangers of Statefullness  Clients can go down at any time.  Client hosts can reboot many times.  The network can lose messages.  The network can duplicate messages. Client/Server Issues 19

Concurrent Server Design Alternatives  One child per client  Spawn one thread per client  Preforking multiple processes  Prethreaded Server Client/Server Issues 20

One child per client  Traditional Unix server:  TCP: after call to accept(), call fork().  UDP: after recvfrom(), call fork().  Each process needs only a few sockets.  Small requests can be serviced in a small amount of time.  Parent process needs to clean up after children!!!!  call wait() Client/Server Issues 21

One thread per client  Almost like using fork  call pthread_create instead  Using threads makes it easier to have sibling processes share information  less overhead  Sharing information must be done carefully  use pthread_mutex Client/Server Issues 22

Pre fork() ’d Server  Creating a new process for each client is expensive.  We can create a bunch of processes, each of which can take care of a client.  Each child process is an iterative server. Client/Server Issues 23

Pre fork() ’d TCP Server  Initial process creates socket and binds to well known address.  Process now calls fork() a bunch of times.  All children call accept().  The next incoming connection will be handed to one child. Client/Server Issues 24

Preforking  Having too many preforked children can be bad.  Using dynamic process allocation instead of a hard-coded number of children can avoid problems.  Parent process just manages the children  doesn’t worry about clients Client/Server Issues 25

Sockets library vs. system call  A preforked TCP server won’t usually work the way we want if sockets is not part of the kernel:  calling accept() is a library call, not an atomic operation.  We can get around this by making sure only one child calls accept() at a time using some locking scheme. Client/Server Issues 26

Prethreaded Server  Same benefits as preforking.  Can also have the main thread do all the calls to accept()  and hand off each client to an existing thread Client/Server Issues 27

What’s the best server design for my application?  Many factors:  expected number of simultaneous clients  Transaction size time to compute or lookup the answer  Variability in transaction size  Available system resources perhaps what resources can be required in order to run the service Client/Server Issues 28

Server Design  It is important to understand the issues and options.  Knowledge of queuing theory can be a big help.  You might need to test a few alternatives to determine the best design. Client/Server Issues 29

Chat: Issues and Ideas for Service Design  Pretend we are about to design a chat system.  We will look at a number of questions that would need to be answered during the design process.  We will look at some possible system architectures. Chat 31

Multi-user Chat Systems Functional Issues  Message types.  Message destinations (one vs. many groups)  Scalability (how many users can be supported)  Reliability?  Security authentication authorization privacy Chat 32

Message Types  Some options:  text only  audio  images  anything MIME: Multipurpose Internet Mail Extensions Chat 33

Message Destinations  Each message goes to a group (multi-user chat)  Can we also send to individuals?  Should we support more than one group? Are groups dynamic or static? What happens when there is nobody in a group? Can groups communicate? Can groups merge or split? Chat 34

Scalability  How large a group do we want to support?  How many groups?  What kind of service architecture will provide efficient message delivery?  What kind of service architecture will allow the system to support many users/groups? Chat 35

Reliability  Does a user need to know (reliably) all the other users that receive a message?  What happens if a message is lost?  resend?  application level or at user level?  What happens when a user quits?  Does everyone else need to know? Chat 36

Security  Authentication  do we need to know who each user is?  Authorization  do some users have more privileges than others?  Privacy  Do messages need to be secure?  Do we need to make sure messages cannot be forged? Chat 37

Peer-to-Peer Service Architecture Chat 38 Client

Peer-to-Peer Service Architecture (cont.) Each client talks to many other clients.  Who’s on first?  Is there a well known address for the service?  How many peers can we keep track of? Chat 39

Client/Server Chat 40 Client Server

Client/Server  Server is well known.  Life is easier for clients  don’t need to know about all other clients.  Security is centralized.  Server might get overloaded? Chat 41

Hybrid Possibility Chat 42 Client Server CONTROL MESSAGES

Hybrid  Clients connect to server and gather control information:  List of other clients.  List of chat groups.  Messages are sent directly (not through server).  Could use connectionless protocol UDP or transaction based TCP Chat 43

Internet Relay Chat  IRC is a widely used multi-user chat system.  Supports many chat groups (channels).  Extensive administrative controls.  Distributed service architecture.  Still in use today, although WWW based chat is now more common. Chat 44

IRC Architecture Chat 45 Client Server Client Server Client

Server Topology  Servers are connected in a spanning tree  Single path between any 2 servers.  New servers can be added dynamically support for preventing cycles in the server graph.  A collection of servers operates as a unified system,  users can view the system as a simple client/server system. Chat 46

Server Databases  Each server keeps track of  all other servers  all users (yes, really all users!)  all channels (chat groups)  Each time this information changes, change is propagated to all participating servers. Chat 47

Clients  A client connects to the system by establishing a TCP connection to any server.  The client registers by sending:  (optional) password command  a nickname command  a username command. Chat 48

Nicknames and user names  A nickname is a user supplied identifier that will accompany any messages sent.  Wizard, kilroy, gargoyle, death_star, gumby  The username could be faked,  some implementations use RFC931 lookup to check it  Users can find out the username associated with a nickname. Chat 49

Collisions  If a client requests a nickname that is already in use, the server will reject it.  If 2 clients ask for the same nickname on 2 different servers,  it is possible that neither server initially knows about the other. Chat 50

Nickname Collision Chat 51 Server A Server A Server B Server B IRC Network Client I want to be the_one Client I want to be the_one

Nickname Propagation  The command used to specify a nickname is forwarded to all other servers  using the spanning tree topology  Extra information is added by the original server:  server name connected to client with nickname.  Hop count from the server connected to the client hop count is IRC server count (not IP!) Chat 52

Channels  2 kinds of channels  local to a server start with ‘&’ character  global, span the entire IRC network start with the ‘#’ character  Users can JOIN or PART from a channel.  A channel is created when the first user JOINS, and destroyed when the last user PARTS. Chat 53

Messages  All messages are text.  A message can be sent to nicknames, channels, hosts or servers.  There are two commands for sending messages:  PRIVMSG: response provided.  NOTICE: no response (reply) generated. Avoids loops when clients are automatons Chat 54

Other Stuff  Special class of users known as Operators.  Operators can remove users!  Servers can be told to connect to another server  operators create the spanning tree  The tree can be split if a node or network fails  there are commands for dealing with this Chat 55

Problems  Scalability  Currently every server needs to know about every other server, every channel, and every user.  Path length is determined by operators, an optimal tree could be generated automatically.  Need a better scheme for nicknames  too many collisions  Current protocol means that each server must assume neighbor server is correct.  Bad guys could mess things up. Chat 56