DOC PREVIEW
UMD CMSC 132 - Networking Support In Java

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Networking Support In JavaTesting (old topic)OverviewClient / Server ModelClient ProgrammingSimple Server ProgrammingSupporting multiple connections / clientsNetworking in JavaJava Networking APIJava Networking ClassesInetAddress ClassInetAddress is a factoryServerSocket ClassServerSocket MethodsSocket ClassSocket MethodsI/OStarting pointsDecorator design patternAdapter design patternSome important factsUDP/Datagram SocketsDatagramPacket ClassDatagramPacket MethodsDatagramSocket ClassDatagramSocket MethodsURL ClassURL ConstructorsURL MethodsURL ReaderNetworking Support In Java Nelson Padua-PerezBill PughDepartment of Computer ScienceUniversity of Maryland, College ParkTesting (old topic)You must write test casesRelease tests are designed so that they don’t give you enough information; you have to write test casesIn many cases, people were failing release tests and if they had written any test for their failing methods, they would have found the errorWe are making some changes to provide better feedback about the quality of your test casesWe will beat on you if you don’t write test casesOverviewNetworkingBackgroundConceptsNetwork applications Java’s objected-oriented viewJava’s networking API (Application Program Interface)Everything you need to know:http://java.sun.com/docs/books/tutorial/networking/index.htmlLast lectureThis lectureClient / Server ModelRelationship between two computer programsClientInitiates communicationRequests servicesServerReceives communicationProvides servicesOther modelsPeer-to-peer (P2P)ClientClientClientServerServerClientClient ProgrammingBasic steps1. Determine server location – IP address & port2. Open network connection to server3. Write data to server (request)4. Read data from server (response)5. Close network connection6. Stop clientSimple Server ProgrammingBasic steps1. Determine server location - port (& IP address)2. Create ServerSocket to listen for connections3. While (true) { 4. accept network connection to client5. Read data from client (request)6. Write data to client (response)7. Close network connection to client8. }Supporting multiple connections / clientsCan support multiple connections / clientsLoopHandles multiple connections in orderLimits on how much traffic we can handleNot resilient in face of slow/stopped clientsMultithreadingAllows multiple simultaneous connectionsNetworking in JavaPackagesjava.net  Networkingjava.io  I/O streams & utilitiesjava.rmi  Remote Method Invocationjava.security  Security policiesjava.lang  Threading classesSupport at multiple levelsData transport  Socket classesNetwork services  URL classesUtilities & securityJava Networking APIApplication Program InterfaceSet of routines, protocols, tools For building software applicationsJava networking APIHelps build network applicationsInterfaces to sockets, network resourcesCode implementing useful functionalityIncludes classes forSocketsURLsJava Networking ClassesIP addressesInetAddressPacketsDatagramPacketSocketsSocketServerSocketDatagramSocketURLsURLInetAddress ClassRepresents an IP addressCan convert domain name to IP addressPerforms DNS lookupGetting an InetAddress objectgetLocalHost()getByName(String host)getByAddress(byte[] addr)InetAddress is a factory You can’t create InetAddress objects by invoking the InetAddress constructorInstead, invoke static methods of the InetAddress classThese methods return either a Inet4Address or a Inet6Addressboth of which extend InetAddressThe factory design pattern delegates responsibility for design what class of object to create to the factoryServerSocket ClassCreate socket on serverConstructor specifies local portServer listens to portUsageBegin waiting after invoking accept()Listen for connection (from client socket)Returns Socket for connectionServerSocket Methodsaccept()close()getInetAddress()getLocalPort()Socket ClassOne end of a TCP connectionClient uses Constructor, providing:Machine name or IP addressPort numberSocket also returned by accept methodTransfer data via streamsstandard Java I/O streamsSocket MethodsgetInputStream() getOutputStream()close()getInetAddress()getPort()getLocalPort()I/O4 fundamental interfacesInputStream - incoming stream of bytesReader - incoming stream of charactersOutputStream - outgoing stream of bytesWriter - outgoing stream of charactersStarting pointsFileInputStream/FileOutputStreamFileReader/FileWriterByteArrayInputStream/ByteArrayOutputStreamStringReader/StringWriterSocket inputStream / outputStreamDecorator design patternThe java I/O libraries demonstrate the decorator design patternYou have some interface X, and a bunch of class that both implement X and take an X object as an argumentA decorate intercepts / monitors / modifiers calls that are usually delegated to the object specified at construction timeFor example, a LineNumberReaderused to decorate any Reader, gives the ability to find out what line number you are currently atAdapter design patternQuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.The I/O libraries also demonstrate the adapter design patternGiven two interfaces, an X-to-Y adapter takes an X object when constructed and implements the Y interfaceY call’s are translated into corresponding X calls on the contained objectFor example, an InputStreamReader takes any InputStream and produces a ReaderSome important factsOnce you have written to a writer or outputStream, it may not be immediately sentflush or close the output stream to ensure the data is sentA socket, it’s inputStream and it’s outputStream are all linkedclosing any one closes all threeHave to carefully choreograph who reads and who writes whenif both ends are reading, waiting for the other to send something, they deadlockUDP/Datagram SocketsCreate DatagramSocketsbound to a portfor clients, can bind to “arbitrary, unspecified but free port”Create DatagramPacketStores data to be sent/received, address and portdestination for packets being sentsource for received packetscan reuse the byte arrays associated with a Datagramavoid allocating arraysDatagramPacket ClassData in packet represented as byte arrayDatagramPacket MethodsgetAddress() getData()getLength()getPort()DatagramSocket ClassCreate UDP socketConstructor specifies portcan let system find arbitrary free portSend / receive DatagramPacketDatagramSocket Methodsclose()getLocalAddress() - only interesting if you have multiple IP addresses on the local


View Full Document

UMD CMSC 132 - Networking Support In Java

Documents in this Course
Notes

Notes

8 pages

Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Download Networking Support In Java
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Networking Support In Java and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Networking Support In Java 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?