Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

A Short Java Socket Tutorial


Published on

Published in: Technology, News & Politics
  • I just want to warn those who learns Java Socket API that the provided sample server is not able to handle concurrent connections (there's really no need to override and start a new thread).
    Are you sure you want to  Yes  No
    Your message goes here

A Short Java Socket Tutorial

  1. 1. A Short Java Socket Tutorial Albert Guo [email_address]
  2. 2. Agenda <ul><li>Java Socket </li></ul><ul><li>Interactive Socket Server Lifecycle </li></ul><ul><li>Lifecycle of a multithreaded socket server </li></ul><ul><li>Use Case Diagram </li></ul><ul><li>Class Diagram </li></ul><ul><li>Socket Server Operations </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li>Socket Client Operation </li></ul></ul><ul><ul><li>Socket Server Demo </li></ul></ul><ul><ul><li>Socket Clients Demo </li></ul></ul>
  3. 3. Java Socket <ul><li>A socket is a communication end point </li></ul><ul><ul><li>Is a network programming interface </li></ul></ul><ul><ul><li>Is used by a process to communicate with a remote system via a transport protocol. </li></ul></ul><ul><ul><li>Needs an IP address and a port number </li></ul></ul><ul><li>Sockets are popularly used in client/server computing </li></ul><ul><ul><li>Provides two major types of services: </li></ul></ul><ul><ul><ul><li>Connection-oriented </li></ul></ul></ul><ul><ul><ul><li>Connectionless </li></ul></ul></ul>
  4. 4. Java Socket – cont. <ul><li>Java supports client/server computing using sockets. </li></ul><ul><ul><li>Java supports both connection-oriented and connectionless services. </li></ul></ul><ul><ul><li>Java uses Socket for clients and ServerSocket for servers in a connection-oriented environment. </li></ul></ul><ul><ul><li>Java uses DatagramSocket/DatagramPacket for connectionless services. </li></ul></ul>
  5. 5. Interactive Socket Server Lifecycle
  6. 6. Lifecycle of a multithreaded socket server
  7. 7. Use Case Diagram
  8. 8. Class Diagram
  9. 9. Socket Server Operations
  10. 10.
  11. 11.
  12. 13. Socket Client Operation
  13. 14. Socket Client
  14. 15. Socket Server Demo Client1’s request Client2’s request
  15. 16. Socket Clients Demo Client1 request for Taipei’s weather condition Client1 request for TaoYuan’s weather condition