Ethernet � broadband or baseband signalling � Hub and repeaters � Ethernet switches and bridges: Ethernet packets � Ethernet topologies � Bus, star, tree. � Carrier-Sense Multiple Access with Collision Detection (CSMA/CD) � All nodes are continuously ‘listening’ to the medium for packets that are addressed to them. � Packets � frames � Prefix: hardware timing purposes � the destination address, the sending address; � length of data (46—1,500 bytes), data of variable length, 1 � checksum 1
Ethernet � Packet collision � carrier sensing: not enough A B time = 0 Message almost there at time T when A B B starts – collision! time = T’ � Collision detection • Sender’s responsibility to detect A B time = 2T � Minimum packet length in collision detection � Send jamming signal, delay and try again � Delay time is selected using binary exponential back-off 2 2
Middleware Applications, services RMI and RPC Middleware request-reply protocol This layers chapter marshalling and external data representation UDP and TCP � Application programming interfaces (APIs) � Examples of middleware services � Remote data access (RDA) -- SQL access to server-based DBMS. � Remote procedure calls (RPC) � Remote method invocation (RMI) � Today’s topics � Interprocess communication (IPC); � Java API for Internet transport protocols � External data representation and marshalling 3 3
InterProcess Communication � two basic models � shared memory � message passing � two basic operations on messages � Send (to, message) � Receive (from, message) A typical communication system 4 4
� Types of communication � Persistent communication – Stores message until communicated to user � Transient communication – Stored only when sending and receiving processes are alive • Transport level protocols provide transient communication � Asynchronous – Sender continues after sending message � Synchronous – Sender blocks until message is stored at receiver's local buffer, delivered to receiver or processed by receiver Example of Persistent Asyn. Comm. : email system 5 5
Transient asynchronous communication: UDP, one- c) way RPCs. Receipt-based transient synchronous communication d) Delivery-based transient synchronous communication e) at message delivery: Asyn. RPCs Response-based transient synchronous communication: f) 6 PRCs, RMIs. 6
IPC mechanisms � Pipes � processes must be related through a common ancestor � impossible in a distributed environment � shared memory � Sockets � 4.4BSD Unix � Java � message queues: Message-oriented Middleware (MOM) agreed port any port socket socket message client server other ports Internet address = 138.37.94.248 Internet address = 138.37.88.249 7 7
Socket Types in 4.4BSD UNIX � Stream socket: provides for the bidirectional, reliable, sequenced, and unduplicated flow of data without record boundary. � Very similar to pipe � Datagram socket: supports bidirectional flow of data which is not promised to be sequenced, reliable, or unduplicated � Reliability guaranteed by high-level apps. � Most widely used in name service, time service. � A raw socket: provides users access to the underlying communication protocols which support socket abstractions. � Not for general users � Sequenced packet socket: No protocol for this typ 8 8
Socket creation: socket() � communication domains � local domain: at the same machine � internet domain: Internet � XNS domain: XEROX Network Systems � s = socket(domain, type, protocol); � A system call � domain : AF_UNIX, AF_INET, or AF_NS � type : SOCK_STREAM, SOCK_DGRAM, etc � protocol : TCP or UDP. Auto selected if 0 � Return a socket descriptor (a small integer for later reference) � Ex: s = socket(AF_INET, SOCK_STREAM, 0); � Creation Failure: Reasons � Lack of memory (ENOBUFS) � Unknown protocol (EPROTONOSUPPORT) � Socket without supporting protocol (EPROTOTYPE) 9 9
Binding Names: bind() � Socket created without a name (i.e. port address) � Process has no way to access it. � System call: bind(s, address, len) � s : socket descriptor � address : <local address, local port> or a path name � len : the length of the address. Connection Establishment � Asymmetric, involving a server and a client � Server: create � bind � listen � accept � Client: create � bind � connect � connect(s, address, len) • s : socket descriptor • address : server address • len : the length of the address 1 0 10
Connection Failure � Timeout (ETIMEDOUT) � Server down or network corrupt � Connection refused (ECONNREFUSED) � Server not ready yet � Network down or server down � operational errors are returned by the underlying communication system � Unknown host � operational errors returned by intermediate gateways or switching nodes. System Call: listen() � listen(s, max_num) � s : socket descriptor � max_num : the maximum number of outstanding connections which may be queued awaiting acceptance by the server process � If the queue is full, a connection will be ignored (instead of refused). Why? 1 1 11
System call: accept() � newsock = accept(s, from-addr, len) � s : socket descriptor � from-addr : to store the address of the client • Usually a pointer, could be null � len : length of from-addr � Return a new socket. � Usually block the caller � Cannot select the client to be accepted. Data Transfer � Once a connection is established, data flow may begin. � write(s, buf, sizeof (buf)); � send(s, buf, sizeof (buf), flags); � read(s, buf, sizeof (buf)); � recv(s, buf, sizeof (buf), flags); � Flags: provide more features 1 2 12
Discarding Sockets � close(s) � Sockets which promises reliable transmission will still attempt transfer data. � Shutdown(s, how), where how is � 0: no more receiving � 1: no more sending � 2: no more receiving or sending server socket() bind() client listen() socket() accept() connect() Start a thread accept() Wait for new read() write() connection read() write() 1 close() close() 3 13
Java Sockets server client socket() socket() accept() Start a thread accept() Wait for new readUTF() writeUTF() connection readUTF() writeUTF() close() close() 1 4 14
Java API for the Internet protocols � Transport address: IP address + port number � java.net.InetAddress Static InetAddress.getByName(String host) � host name: “java.sun.com” � getHostAddress() : IP address string in textual presentation. � getHostName(): the host name for this IP address. � 32-bit integers for port number � Socket types � UDP socket � TCP socket 1 5 15
UDP socket � Data unit: datagram � Called datagram socket � Socket must be bound to a local port and one IP address � Server: well-known port � Client: any free one � issues related to datagram communication � Message size � non-blocking send operations and blocking receive operations � Timeouts � applications use UDP: Domain Naming Service, Voice Over IP 1 6 16
UDP socket � Encapsulated in Class DatagramSocket � Datagram: Class DatagramPacket � DatagramSocket. send (DatagramPacket) � DatagramSocket. receive (DatagramPacket) � DatagramSocket. setSoTimeout (int timeout) � DatagramSocket. connect (InetAddress, int port ) � public DatagramPacket (byte[] buf, int length, InetAddress address, int port) 1 7 17
TCP socket � TCP is a connection-oriented protocol, a connection is established first. � Server listens connection request � Client asks for a connection � Two types of TCP sockets: ordinary sockets and server sockets � A client process constructs an ordinary socket and then it asks for a connection with the server. � A server socket receives a connection request, it constructs an ordinary socket with an unused port number which completes the connection. � No limit on data size. � Streams: one in each direction 1 8 18
Some issues in stream communication � Matching of data items � Blocking � Threads � Applications use TCP: HTTP, FTP, Telnet, SMTP. � ordinary TCP socket: Socket � server socket: ServerSocket � ServerSocket(int port), or ServerSocket.bind(SocketAddress, int port); � Socket ServerSocket.accept(); � InputStream and OutputStream classes � An example in textbook 1 9 19
Message-oriented Middleware (MOM) � Main features � intermediate-term storage for messages: persistent ! � neither sender nor receiver is required to be active � Message queue � eliminate the need for programs to be logically connected: asynchronous ! � takes minutes � Only guarantee is that a message will be inserted in receivers’ queue. But no guarantees about when, or even if the message will actually be read � Source queue & destination queue � Queue managers: Message Queue Interface (MQI) � Overlay network 2 0 20
Recommend
More recommend