/
Networking with Java Networking with Java

Networking with Java - PowerPoint Presentation

cheryl-pisano
cheryl-pisano . @cheryl-pisano
Follow
348 views
Uploaded On 2019-11-08

Networking with Java - PPT Presentation

Networking with Java CSc 335 ObjectOriented Programming and Design Spring 2009 Networking with Java N 2 Acknowledgements These slides were written by Craig Barber Some slides from Martin Stepp were used ID: 764559

networking java server socket java networking socket server sockets connection throws process clients computer serversocket peer streams host input

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Networking with Java" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009

Networking with Java N- 2 Acknowledgements These slides were written by Craig Barber. Some slides from Martin Stepp were used. The slides were modified slightly by Richard Snodgrass and reorganized by Ivan Vazquez.

Networking Refactoring Y- 3 Refactoring Y- 3 Refactoring Y- 3 Concurrency Networks Serialization Javadoc JUnit Eclipse Debugging Testing & Maintaing Large Programs Teams Reading others’code MVC ObserverObservable DesignPatterns UML ClassDiagrams InheritanceHierarchy Coupling/Cohesion OO Design PITL SequenceDiagrams PackageDiagrams AnonymousClasses AbstractClasses Packages JDK/JRE Java Language Compile-TimeRun-Time Type ResolutionType Checking Java Swing Frameworks Java API Inversion of Control Layout Manager Listeners Events I/O Iterator Collection Exceptions Composite Command Template Decorator N - 3

Networking with Java N- 4 Outline Introduction to Networking Concepts Client-Server and Peer-to-Peer Sockets Streams Networking in Java Summary

Networking with Java N- 5 What is “Networking” What is “Networking”? Basic: getting two or more computers to send data to each other Practical: having programs on separate computers interact with one another Types of Networking Client - ServerMany clients connect with one server.Clients communicate only with server.Peer-to-Peer Clients connect to a group of other clients, with no server.Clients communicating directly with each-other.

Networking with Java N- 6 Client - Server Networking Advantages: Easier to implement Less coordination involved Easier to maintain control of users Disadvantage: Relies on one main server for entire operation

Networking with Java N- 7 Peer-to-Peer Networking Advantages: No main server Easier for clients to enter and leave Easier for spreading updates Disadvantages: Less control over users Harder to coordinateMore difficult to implement code

Networking with Java N- 8 How Does Networking Work? Computers connect to each other through links called sockets , each associated with a single computer. A network stream is created by connecting a socket on one computer to a socket on another computer. Applications communicate by sending data through streams to each other.Note: streams are also used in Java for input and output.

Networking with Java N- 9 Sockets A socket is a connection on one computer used to send data back and forth The application consists of multiple processes, one running on each computer. Sockets are created by the process on each computer. The sockets then establish a connection to each other. One process sets up a server socket to receive a connection. The other process sets up a client socket to establish the connection with the server socket.

Networking with Java N- 10 Outline Introduction to Networking Concepts Networking in Java Sockets Streams Decorating StreamsSummary

Networking with Java N- 11 Sockets in Java Found in java.net package java.net.ServerSocket Accepts new incoming connections Creates new ServerSocket for each connectionjava.net.SocketConnects to an existing ServerSocket, through the network

Sockets in Java Networking with Java N- 12 Host Machine Process Host Machine Process Server Socket Input Socket Out put Socket Socket Socket Socket Input Socket Process Socket Host Machine

Networking with Java N- 13 java.net.ServerSocket public ServerSocket( int port ) Throws IOException Creates a ServerSocket to accept new connections at the specified port public Socket accept( )Throws IOExceptionWaits for an incoming connection, establishes the new connection, and returns a socket for that connection Multiple applications can connect to the same ServerSocketpublic void close( )Throws IOExceptionCloses the server socket. Does not close open sockets.

Networking with Java N- 14 java.net.Socket public Socket( String host, int port ) Throws IOException , UnknownHostException Connects to a server socket at the provided address (host) on the provided portpublic InputStream getInputStream( )Throws IOExceptionReturns the input stream from the socketpublic OutputStream getOutputStream( )Throws IOExceptionReturns the output stream from the socket public void close( )Throws IOExceptionCloses the connection

Networking with Java N- 15 Summary Networking is actually doable, when using Java’s convenient API . Networking is integrated with input and output: both use streams. Decorators make your life much easier. Advanced applications often use serialization and threads.