Presentation is loading. Please wait.

Presentation is loading. Please wait.

Building an ftp client and server using sockets we now know enough to build a sophisticated client/server application!  ftp  telnet  smtp  http.

Similar presentations


Presentation on theme: "Building an ftp client and server using sockets we now know enough to build a sophisticated client/server application!  ftp  telnet  smtp  http."— Presentation transcript:

1 Building an ftp client and server using sockets we now know enough to build a sophisticated client/server application!  ftp  telnet  smtp  http

2 Implementation: the socket data structure within the OS, one such data structure per socket:

3 socket data structure (cont.)

4 Implementation: OS actions on sendto()

5 Implementations: OS actions on rcvfrom()

6 UNIX SVR4: TLI Interface Transport Layer Interface for Unix System V, Release 4 (svr4)  like sockets:  transport independent  two modes: connection-oriented, datagram  ``transport endpoint'' is like a socket  TLI implemented as user-level C library routines rather than system calls

7 Some TLI versus socket comparisons

8 Windows Sockets Based on BSD sockets:  BSD: ``the de facto standard for TCP/IP Networking'' (quote from Winsock1.1 documentation)  supports stream(TCP)/datagram(UDP) model  API the same as what we have seen A few differences/incompatibilities:  extensions for asynchronous programming  different error return codes: -1 not the error return code!  socket identifier different from file identifier  read(), write(), close() should not be used  use socket-specific equivalents instead

9 Windows Sockets: System Calls * = The routine can block if acting on a blocking socket.

10 Windows Sockets: System Calls (cont) * = The routine can block if acting on a blocking socket.

11 Windows Sockets: database functions * = the routine can block under some circumstances * = the routine can block under some circumstances.

12 Windows Sockets: asynchrony asynchronous support: allows programmer to specify routine to be called when socket-related event occurs:  socket ready for reading/writing  out-of-band data ready for reading  socket ready to accept connection  connection closed these extensions help with concurrent, multithreaded Windows programming

13 Windows Sockets: asynchrony(cont)

14 Network Programming in Java  network API abstraction: socket  transport service classes same as with sockets:  datagram: UDP  connection-oriented: TCP  a slightly (only) higher-level interface than with UNIX sockets  low level system calls (those we've seen for UNIX) also available  some JAVA-specific considerations:  applets can connect only to servers from whence they came (security)  JAVA garbage collects unused objects  excellent reference: Java in a Nutshell, 2nd ed. D. Flanagan, O'Reily and Associates, 1997 Java in a Nutshell, 2nd ed. D. Flanagan, O'Reily and Associates, 1997Java in a Nutshell, 2nd ed. D. Flanagan, O'Reily and Associates, 1997

15 Sending a Datagram in Java  create a DatagramPacket, specifying data, length, dest. IP address/port  invoke send() method (procedure) of DatagramSocket // This example is from the book _Java in a Nutshell_ by David Flanagan. // Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. // You may study, use, modify, and distribute this example for any purpose. // This example is provided WITHOUT WARRANTY either expressed or implied. import java.io.*; import java.net.*;

16 // This class sends the specified text as a datagram to port 6010 of the specified host. public class UDPSend { static final int port = 6010; public static void main(String args[]) throws Exception { if (args.length != 2) { System.out.println("Usage: java UDPSend "); System.exit(0); } // Get the internet address of the specified host InetAddress address = InetAddress.getByName(args[0]); // Convert the message to an array of bytes int msglen = args[1].length(); byte[] message = new byte[msglen]; args[1].getBytes(0, msglen, message, 0);

17 // Initilize the packet with data and address DatagramPacket packet = new DatagramPacket(message, msglen, address, port); // Create a socket, and send the packet through it. DatagramSocket socket = new DatagramSocket(); socket.send(packet); }

18 Receiving a Datagram in Java  create a DatagramPacket with a buffer to receive packet  create a DatagramSocket that will "listen" for packet  invoke receive() method (procedure) of DatagramSocket

19 Receiving a Datagram in Java (cont) // This example is from the book _Java in a Nutshell_ by David Flanagan. // Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. // You may study, use, modify, and distribute this example for any purpose. // This example is provided WITHOUT WARRANTY either expressed or implied. import java.io.*; import java.net.*;

20 // This program waits to receive datagrams sent to port 6010. // When it receives one, it displays the sending host and port, // and prints the contents of the datagram as a string. public class UDPReceive { static final int port = 6010; public static void main(String args[]) throws Exception { byte[] buffer = new byte[1024]; String s; // Create a packet with an empty buffer to receive data DatagramPacket packet = new DatagramPacket(buffer, buffer.length); // Create a socket to listen on the port. DatagramSocket socket = new DatagramSocket(port);

21 Receiving a Datagram in Java (cont) for(;;) { // Wait to receive a datagram socket.receive(packet); // Convert the contents to a string s = new String(buffer, 0, 0, packet.getLength()); // And display them System.out.println("UDPReceive: received from " + packet.getAddress().getHostName() + ":" + packet.getPort() + ": " + s); }

22 Critical Assessment of Socket API “good” things about sockets/TLI/winsock/Java network API: “bad” things about socket API:

23 Novell Networks: Netware API

24  adopts client-server paradigm  data transport: unreliable datagram (IPX) or connection- oriented reliable (SPX)]  SAP: Service Advertising Protocol used to advertise/request services  NCP: Netware Core Protocol used for Netware-defined client- server interactions  higher-level Netware-defined services:  directory services  transaction support  resource control  lock services

25 Novell SAP protocol  allows clients/servers to locate advertise services  routers and gateways maintain table of known services  broadcast service info periodically  different than Internet model: inside of Novell network (routers) have application-level info  SAP broadcasts IPX packets. Sample format:  service types defined by Novell.

26 Novell SAP protocol (cont) Possible operations:

27 OSI Application Service Entities  applications can call (communicate with) predefined existing entities that provide a service  reliable transfer service element:  checkpointing and recovery: reliable data transfer in face of network connection failures  two-way alternating communication: confirm transfer and receipt before sending next message  commitment, concurrency and recovery provides an atomic action:  set of message exchanges and processing all guaranteed to execute to completion or else as if no action had occurred  nothing left dangling should network fail  two phase commit: one master, many slaves

28 API: Summary  some API’s provide only low-level interface to transport services: socket, winsock, TLI  other API’s provide higher-level services (e.g., transaction support, service advertising or request)  makes building applications easier  sockets the de facto standard  FYI reading:  winsock: http://www.sockets.com winsock: http://www.sockets.com winsock: http://www.sockets.com  JAVA: http://java.sun.com JAVA: http://java.sun.com JAVA: http://java.sun.com


Download ppt "Building an ftp client and server using sockets we now know enough to build a sophisticated client/server application!  ftp  telnet  smtp  http."

Similar presentations


Ads by Google