Communication. References r On-line tutorials m Beej’s Guide to Network programming m The Java.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Remote Procedure Call (RPC)
CCNA – Network Fundamentals
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public ITE PC v4.0 Chapter 1 1 OSI Transport Layer Network Fundamentals – Chapter 4.
Socket Programming Application Programming Interface.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Chapter 3: Transport Layer
Socket Programming.
Network Programming UNIX Internet Socket API. Everything in Unix is a File –When Unix programs do any sort of I/O, they do it by reading or writing to.
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.
8-1 Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable data transfer m flow.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Process-to-Process Delivery:
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Communication. References Chapter 3, Tanenbaum and Van Steen Beej’s Network Programming Guide.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Review: –What is AS? –What is the routing algorithm in BGP? –How does it work? –Where is “policy” reflected in BGP (policy based routing)? –Give examples.
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.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Transport Layer1 Ram Dantu (compiled from various text books)
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
Communication. References r The 402 web site has many links to socket tutorials. r Chapter 2.1 of the Tanenbaum, van Steen textbook r Chapter 15, of the.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
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.
Transport Layer 3-1 Chapter 3 Outline r 3.1 Transport-layer services r 3.2 Multiplexing and demultiplexing r 3.3 Connectionless transport: UDP.
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
Socket Programming Lab 1 1CS Computer Networks.
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,
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
UNIX Internet Socket API
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
MULTIPLEXING/DEMULTIPLEXING, CONNECTIONLESS TRANSPORT.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2: Transport Layer 11 Transport Layer 1. 2: Transport Layer 12 Part 2: Transport Layer Chapter goals: r understand principles behind transport layer services:
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.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
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.
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Transport layer API: Socket Programming
Process-to-Process Delivery:
Socket Programming.
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Presentation transcript:

Communication

References r On-line tutorials m Beej’s Guide to Network programming m The Java Tutorials: All about sockets working/sockets/ working/sockets/ r Chapter 2.1 of the Tanenbaum, van Steen textbook r Chapter 15, of the Steven’s book on TCP/IP

Protocols r All communication is based on exchanging messages. r A protocol is a set of rules which is used by computers to communicate (using messages) with each other across a network. r Protocols control the sending and receiving of messages m e.g., TCP, IP, HTTP,FTP

Protocol Stacks r A computer is connected to the Internet and has a unique address r Let’s say that an application on computer A wants to send the message “Hello there” to an application computer B r The text message must be translated into electronic signals, transmitted over the Internet, then translated back into text. r This is accomplished using a protocol stack

Protocol Stacks r The protocol stack is usually built into the computer’s operating system r The protocol stack used on the Internet is referred to as the TCP/IP protocol stack because of the two major communication protocols used (more later).

Internet Protocol Stack r Many different protocols are needed at a variety of levels r A message starts at the top of the protocol stack and works its way downwards. r If the message is long, then the message may be broken up into smaller chunks of data r These chunks are known as packets. r Packets go to the transport layer application transport network link physical

Transport Protocols r At the sending end each packet is associated with a destination address and a port number m A destination address is insufficient since there could be multiple processes receiving messages m A port number allows for an identification of a process that is to receive the packet

Transport Protocols r At the receiving end, the transport layer has to put back together the pieces into the message before passing it to the application. r One of the Internet transport protocols is called Transmission Control Protocol (TCP). m TCP is a reliable transport protocol i.e., it can deal with losses r The Internet transport protocol that does not deal with losses is called User Datagram Protocol (UDP).

Network Layer r For a message to get from the sender to the receiver there are often multiple paths that can be taken r A path consists of multiple routers r Choosing a path is called routing r Most widely used network protocol is the connectionless IP (Internet Protocol)

Data Link Layer r Between path points, a mechanism is needed to detect and correct errors such as damaged or lost messages r Basically the data link layer is concerned with data transfer between the path points r The data link layer groups bits into units (frames). Each frame has m Sequence numbers for detecting lost messages m Checksums for detecting damage

Physical Layer r The physical layer is concerned with the transmission of 0’s and 1’s. m How many volts to use for 0 and 1? m How many bits per second can be sent? r Many physical layer standards have been developed for different media e.g., m RS-232-C standard for serial communication lines

Application Layer Protocols r Application layer protocols include ftp and http. r These protocols are built on top of TCP/UDP

Client-Server Paradigm r Many network applications use a form of communication known as the client-server paradigm m Server application waits (passively) for contact. m Client initiates the contact. r Client and server applications interact directly with a transport-layer protocol for establishing communication and to send and receive information. r The transport layer uses lower layer protocols to send and receive individual messages.

Application Programming Interface: API r The interface an application uses when it interacts with the transport protocol software is known as an Application Programming Interface (API). r An API defines a set of operations that an application can perform when it interacts with a protocol. r APIs are defined as follows: m Provide a set of procedures that can be called m For each procedure, define the arguments expected m Usually there is a procedure for each basic operation e.g., send, receive

Socket API r Introduced in 1981 r Originally only Unix r Implemented as a library r This can be used to communicate with TCP or UDP

Sockets r Sockets provide an interface to TCP/IP and UDP/IP r A socket is characterized by the following information representing communication endpoints m communication protocol, local address, local port, remote address, remote port r Let us now look at how sockets are represented in operating systems

Open Files/Socket Representation r Here is a code fragment FILE *in_file; // open a file in_file = fopen("list.txt", "r"); r Each process has a file descriptor table r An entry could point to information about a file r File information includes disk location, file status etc; r Read/write operations need this info File Descriptor table stdin stdout stderr in_file

Open Files/Socket Representation r An entry can also point to a socket r Socket information is information needed for communication m transport protocol m Address of the local machine m address of the remote machine m Port numbers File Descriptor table stdin stdout stderr in_file socket

Sockets and Descriptors r Sockets are integrated with I/O. r The OS provides a single set of descriptors for files, devices, communication. r The read() and write() functions can be used for both files and communication

Sockets and Descriptors r Before an application can communicate, it must request that the operating system create a socket to be used for communication. r The system returns a small integer (index in the file descriptor table) that identifies the socket. r The application uses that small integer as an argument in one of the communication API procedures.

Socket Creation r descriptor = socket(domain, type, protocol) m domain specifies the specifies the addressing format to be used by the socket. AF_INET specifies Internet address and AF_UNIX specifies file path names. m type specifies the type of communication the socket will use. SOCK_STREAM: connection-oriented stream transfer SOCK_DGRAM: connectionless message-oriented transfer m protocol specifies a particular transport protocol; usually 0 = default for type; keep in mind that there are variations of TCP; m –1 is returned if an error occurs.

Socket Creation r Example #include if ((s = socket(AF_INET, SOCK_STREAM, 0) ) < 0){ perror(“socket”);}

Endpoint Addresses r A socket association is characterized as follows: m communication protocol, local address, local port, remote address, remote port r Local address, port are defined using the bind() call r Remote address, port are defined using connect() call

Address Representation r This structure holds socket address information for many types of sockets. struct sockaddr { unsigned short sa_family; // address family, char sa_data[14]; // 14 bytes of protocol address }; sa_family represents the address format i.e., AF_INET. sa_data contains an address and port number for the socket. r This structure is considered “unyieldy” since most programmers do not want to pack sa_data by hand. r Programmers deal with the sockaddr_in structure

Address Representation r Internally an address is represented as a 32-bit integer struct in_addr { u_long s_addr; } struct sockaddr_in { short sin_family; u_short sin_port struct in_addr sin_addr char sin_zero[8]; } r sin_family represents the address format r sin_port specifies a port number which is associated with a process. r sin_addr specifies the address of a host machine r sin_zero is used to fill out the structure.

Address Representation r sockaddr_in is used for TCP (connection- oriented) and sockaddr_un is used for UDP (connectionless) r The API procedures assume that a variable that is a pointer to sockaddr is used. r The programmer should cast a variable of type sockaddr_in (or sockaddr_un) to a variable that is a pointer to sockaddr

Data Representation r Integers are not represented the same on all machine architectures m little endian: least significant byte first; the Intel series, VAX m big endian: most significant byte first (this is network byte order); IBM 370, Motorola and Sun Sparc r When little endian computers are going to pass integers over the network (e.g., IP addresses), they need to convert them to network byte order.

Data Representation r m = ntohl(m): network to host byte order (32 bit) r m = htonl(m): host to network byte order (32 bit) r m = ntohs(m): network to host byte order (16 bit) r m = htons(m): host to network byte order (16 bit)

Address Conversion r host name to IP address: gethostbyname() r IP address to name: gethostbyaddr()

bind () r bind(int socket,struct sockaddr *localaddr, int addrlen ) m localaddr is a structure that specifies the local address to be assigned to the socket. m addrlen specifies the length of the sockaddr structure pointed to by the address argument. r Used by both TCP and UDP.

bind() struct sockaddr_in sin; if ((s = socket(AF_INET, SOCK_STREAM,0)) < 0 { /*error*/}; memset((char *) &sin, 0, sizeof(sin)); sin.sin_family = AF_INET: sin.sin_port = htons(6000); sin.sin_addr.s_addr = htonl(INADDR_ANY); if bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {…}

connect() r Client contacts server by m Specifying IP address, port number of server process m Calling the connect() system call

connect() r int connect(int s, struct sockaddr *name, int namelen) m client issues connect() to establish remote address and port m Establish connection (stream socket) r The call fails if the host is not listening to port.

send() r int send(int socket, const void *msg, int len, int flags); m msg specifies a pointer to the first of the data to be sent m len is an integer that specifies the amount of data to be sent m flags are used to specify special options which are mostly intended for system debugging (don’t worry about this; just set it to 0) r Used for stream communications

recv() r int recv(int socket, void *msg, int len, int flags); Similar to send() except this is used to receive data and put into msg

listen() r Client must contact server m For a client to contact a server, the server process must first be running m The server must have created a socket that is used to welcome the client’s contact m The server must be “listening” for the client’s contact by using the listen() system call.

listen() r int listen(int s, int queuesize) m queuesize specifies a length for the socket’s request queue. m The OS builds a separate request queue for each socket. m Client requests are put into the queue. m Socket being listened to can’t be used for client. m Note: TCP assumes that for any data is sent that the client process sends a message first, then receives a message from the server and acknowledges that messages (three way handshake).

accept() r When contacted by client, server TCP creates a new socket for the server process to communicate with the client m Allows server to talk with multiple clients

accept() r int accept (int s, struct sockaddr *addr, int *addrlen); m All servers begin by calling socket to create socket and bind to specify a protocol port number. m These two calls are sufficient for a server to start accepting messages in a connectionless transport. m An extra call ( accept() ) is needed for a connection- oriented protocol. m accept() fills in fields of argument addr with the address of the client that formed the connection and sets addrlen to the length of the address. m A socket descriptor is returned

accept() r The server uses the new socket to communicate with the client and then closes the socket when finished. r The original socket remains unchanged and this is used to accept the next connection from a client.

Getting IP address/port from socket int getsockname(int sockfd, struct sockaddr *localaddr, socklen_t *addrlen ) m Get the local IP/port bound to socket int getpeername(int sockfd, struct sockaddr *remoteaddr, socklen_t *addrlen) m Get the IP/port of remote endpoint

close EOF listen bind Sequence of Socket System Calls Client Server socket accept connect Connection request receive sendreceive send

Example (Stream Socket; setting address) setaddr(struct sockaddr_in *sp, char *host, int port) { struct hostent *hp; hp = gethostbyname(host); if (hp == NULL) { fprintf(stderr, "%s: unknown host\n", host); exit(1); } sp->sin_family = AF_INET; bcopy(hp->h_addr, &sp->sin_addr, hp->h_length); sp->sin_port = htons(port); }

Example (Stream Socket; socket creation) streamsocket(int port) { int s; struct sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(port); s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) error("socket"); if (bind(s, (struct sockadd_in *) &sin, sizeof (sin)) < 0) error("bind"); return s; }

Example (Stream Socket; client) main(int argc, char * argv) { struct sockaddr_in sin; int s, n, zero; char buf[BUFSIZ]; myname = argv[0]; if (argc < 2) { fprintf(stderr, "usage: %s port [host]\n", myname); exit(1); }

Example (Stream Socket; client) s = streamsocket(0); /* port 0 means "any port" */ setaddr(&sin, argc > 2 ? argv[2] : "localhost", atoi(argv[1])); /* connect a socket using name specified by the command line */ if (connect(s, (struct sockaddr_in *) &sin, sizeof(sin)) < 0) error("connecting stream socket"); exit(1); }

Example (Stream Socket; client) printf("Type in text\n"); /* read text from the standard input */ while ((n = read(0, buf, sizeof(buf))) > 0){ /* send the text through socket */ if (write(s, buf, sizeof(buf)) < 0) error("writing on stream socket"); bzero(buf, sizeof(buf)); } close(s); exit(0); }

Example (Stream Socket; server) #include char *myname; #define MSGSIZE 1

Example (Stream Socket; server) main(argc, argv) char *argv[]; { struct sockaddr_in from; int s, n, fromlen, msgs, rval; struct hostent *hp; char buf[BUFSIZ]; myname = argv[0];

Example (Stream Socket; server) if (argc < 2) { fprintf(stderr, "usage: %s port\n", argv[0]); exit(1); } s = streamsocket(atoi(argv[1])); fromlen = sizeof(from); if (getsockname(s, &from, &fromlen)) { error("getting socket name"); exit(1); } printf("Socket has port # %d\n",ntohs(from.sin_port)); listen(s, 5);

Example (Stream Socket; server) for (;;) { /*start accepting connections*/ msgs = accept(s, 0, 0); if (msgs == -1) error("accept"); else do { bzero(buf, sizeof(buf));

Example (Stream Socket; server) if ((rval = read(msgs, buf, sizeof(buf))) < 0) error("reading stream message"); if (rval == 0) printf("Ending connection\n"); else { printf("%s\n",buf); }

UDP: User Datagram Protocol [RFC 768] r “no frills,” “bare bones” Internet transport protocol r “best effort” service, UDP segments may be: m lost m delivered out of order to app r connectionless: m no handshaking between UDP sender, receiver m each UDP segment handled independently of others

Why use UDP instead of TCP r No connection establishment (which can add delay) m Remember that TCP does a three-way handshake before transmitting data. UDP does not. r TCP maintains connection state m Receive and send buffers m Sequence and acknowledgement numbers m Congestion control parameters r Smaller segment overhead m Each TCP segment has 20 bytes of header overhead while each UDP segment has 8 bytes. m The overhead in TCP includes sequence and acknowledgement numbers, and a flow congestion field. r There is no congestion control m UDP can blast away as fast as possible

UDP r Often used for streaming multimedia apps m loss tolerant m rate sensitive r Other UDP uses (why?): m DNS m ping command

Applications using UDP and TCP r – TCP r telnet – TCP r HTTP – TCP r ftp – TCP r Remote file server (NFS) – typically UDP r DNS – typically UDP r Streaming multimedia – typically UDP r Internet telephony – typically UDP r Network management (SNMP) – typically UDP

UDP and Reliability r Lack of congestion control r It is possible to have reliable data transfer in UDP. m The application must have acknowledgements and retransmission mechanisms m Streaming applications do this.

API for UDP r socket() call uses SOCK_DGRAM instead of SOCK_STREAM r There is no connect() call r Uses recvfrom() and sendto() instead of read() and write() r There are no listen() or accept() calls

sendto() r int sendto (int socket, char *msg, int len, int flags, struct sockaddr *to, int tolen); m to specifies the destination address and tolen specifies the length of the destination address. r Used for datagram communications

recvfrom() r int recvfrom (int socket, char *msg, int len, int flags, struct sockaddr *from, int fromlen); m sets from to source address of data m sets fromlen to valid length of from m returns number of bytes received

Other Functions r There are other functions used in TCP/UDP that can be used to provide for timeouts,etc; r We will discuss the use of the select() function.

select() int select(int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); FD_CLR(int fd, fd_set *fds); /* clear the bit for fd in fds */ FD_ISSET(int fd, fd_set *fds); /* is the bit for fd in fds */ FD_SET(int fd, fd_set *fds); /* turn on the bit for fd in fds */ FD_ZERO(fd_set *fds); /* clear all bits in fds */ r maxfds: number of descriptors to be tested m descriptors (0, 1,... maxfds-1) will be tested r readfds: a set of fds we want to check if data is available m returns a set of fds ready to read m if input argument is NULL, not interested in that condition r writefds: returns a set of fds ready to write r exceptfds: returns a set of fds with exception conditions

select() int select(int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); struct timeval { long tv_sec;/* seconds / long tv_usec;/* microseconds */ } r timeout m if NULL, wait forever and return only when one of the descriptors is ready for I/O m otherwise, wait up to a fixed amount of time specified by timeout if we don’t want to wait at all, create a timeout structure with timer value equal to 0

select() r A select statement can be used to implement timeouts …. s = streamsocket(0); /* port 0 means "any port" */ setaddr(&sin, argc > 2 ? argv[2] : "localhost", atoi(argv[1])); /* connect a socket using name specified by the command line */ if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) { error("connecting stream socket"); exit(1); } buf = (char *) malloc(BUFSIZ*sizeof(char)); sprintf(buf, "%d", AREYOUUP); write(s,buf,sizeof(buf));

select() tv.tv_sec = 20; tv.tv_usec = 5000; FD_CLR(s,&readfds); FD_ZERO(&readfds); FD_SET(s,&readfds); while (select(s,&readfds,NULL,NULL,&tv) < 0) { }; if (FD_ISSET(s,&readfds)){ printf("Data Arrived\n"); recv(s,buf,sizeof(buf),0); printf("buffer is %s\n",buf); } else printf("timed out\n"); close(s); exit(0); }

Difficulties in Socket Programming r Data representation r Binding

Data Representation r Complex data structures must be converted m Sender must flatten complex data structures m Receiver must reconstruct them r Sender and receiver must agree on a common format for messages.

Example typedef struct { char Name[MAXNAMELENGTH]; float Salary; char JobCode[IDNUMLENGTH]; } Employee You may want to send this information to the server using send(s, (void *) &e, sizeof(e), 0) where e is of type Employee ; This is most likely not going to work. The sender and receiver must agree on a format for the message.

Data Representation r Sender and receiver must agree on type of message. This can can be quite difficult. r Sender must convert data to send to the agreed upon format. This often requires a “flattening” of the data structure representing this data. r Receiver should parse the incoming message.

Data Representation r Code segment for marshalling the Employee structure char *msg; char name[MAXNAMELENGTH]; char jobcode[MAXNAMELENGTH]; float salary; int msglength; Employee e; …. salary = GetSalaryFromEmployee(e); GetJobCodeFromEmployee(e,jobcode); GetNameFromEmployee(e,name); msg = (char *) malloc(sizeof(Employee)); sprintf(msg,"%s %f %s",name,salary,jobcode); ….. msglength = sizeof(Employee); send(s, (void *) msg, msglength));

Data Representation r Code segment for unmarshalling the Employee data sent char *msg; char name[MAXNAMELENGTH]; char jobcode[MAXNAMELENGTH]; float salary; int msglength; Employee e; … msg = (char *) malloc(sizeof(Employee)); … msglength = sizeof(Employee); recv(connectfd, (char *) msg, msglength,0); sscanf(msg, “%s %f %s”, name, &salary, jobcode); …

Other Representational Issues r Usually in a client-server model, the server provides a set of services. Each service can be invoked by a procedure. For example, in an employee management system you would have services that include: m Insert an employee record for a new employee m Get the salary of an employee m Etc; r The client must identify the service that it wants. r This is part of the message.

Other Representational Issues r Thus each service must have an identifier e.g., in the previous code segment examples we may have something like this: sprintf(msg,“%d %s %f %s",methodidentifier, name,salary,jobcode); sscanf (msg,“%d %s %f %s",&methodidentifier, name,&salary,jobcode) ;

Other Representational Issues r What if we have a list of Employees that we want to send in a message? r We do not know ahead of time how many employee records will be sent in a message. r One way to handle this: m Send a message with the service identifier and the number of employee records being sent. m You then send the employee records.

Other Representational Issues r What was just described works fine if the client and server machines have similar machine types. r However, it is common that there are multiple machine types. m IBM mainframes use the EBCDIC character code, but IBM PCs use ASCII. m It would be rather difficult to pass a character parameter from an IBM PC client to an IBM mainframe server using what has just been described. m Similar problems occur with integers (1’s complement vs two’s complement).

Other Representational Issues r Need a canonical form r For the UNIX OS there is XDR(eXternal Data Representation). For Java RMI, there is Java Remote Method Protocol (JRMP).

Binding r Binding refers to determining the location and identity (communication identifier) of the callee m In UNIX, a communication identifier is a socket address containing host’s IP address and port number.

Binding r Strategies for binding m Static binding (which binds the host address of a server into the client program at compilation time) is undesirable. The client and server programs are compiled separately and often at different times. Services may be moved from one host to another. m Could pass host name and port by reading a file or through the command line. You do not need to recompile Client still needs to know the location of the server ahead of time.

Binding r Strategies for binding (cont) m Always run the binder on a “well-known” address (i.e., fixed host and port) m The operating system supplies the current address of the binder (e.g., via environment variable in UNIX). Users need to be informed whenever the binder is relocated Client and server programs need not be recompiled m Use a broadcast message to locate the binder The binder can be easily relocated Client/Server programs need not be recompiled

Binding r Dynamic binding service is desirable. Ideally, a binding service would have the following characteristics: m Allows servers to register their exporting services m Allows servers to remote services m Allows clients to lookup the named service

Summary r This section briefly summarizes the basic message passing primitives that can be used by processes in a distributed application.