1 / 12

Java Networking

Java Networking. Yoshi. What we have learnt before. Java I/O Decorator pattern (Very important!) Use java.net.Socket to connect to a server Have you tried it?. A Case Study. Let’s implement a Tiny HTTP Server First, we have to know something about HTTP protocol

aerona
Télécharger la présentation

Java Networking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Networking Yoshi

  2. What we have learnt before • Java I/O • Decorator pattern (Very important!) • Use java.net.Socket to connect to a server • Have you tried it?

  3. A Case Study • Let’s implement a Tiny HTTP Server • First, we have to know something about HTTP protocol • http://en.wikipedia.org/wiki/HTTP

  4. Tiny HTTP Server • Method outline • startServer • Waiting for client request • makeGUI (Not important here) • Draw a close button on the screen • processClient • Handle the HTTP Request • release • Release the port 80 • main • Check the source code!

  5. Tiny HTTP Server • What’s the problem with this version? • How many connections can it handle at the same time?

  6. Threadless Wait for connection Handle

  7. Threaded Version • Review java.lang.Thread and java.lang.Runnable • Remember that we have two ways to create threads! • Why? • Check the source code! • What the difference parts?

  8. Threaded New Thread! Wait for connection New Thread! New Thread!

  9. Can we make it better? • Can we run web-based application? • PHP, ASP, JSP…etc • Is it hard? • We have a competitor • Jetty • http://www.mortbay.org/jetty/

  10. Tools • Firefox add-on plug-in • HttpFox • Wireshark (known as Ethereal before)

  11. Summary • java.io.* • http://java.sun.com/j2se/1.5.0/docs/api/java/io/package-summary.html • java.net.* • http://java.sun.com/j2se/1.5.0/docs/api/java/net/package-summary.html • Check it out!

  12. Exercise Expand the functionalities of this Tiny HTTP Server

More Related