A Short Java Socket Tutorial

0 views
16,717 views

Published on

Published in: Technology, News & Politics
1 Comment
6 Likes
Statistics
Notes
  • 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 Runnable.run() and start a new thread).
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
0
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
559
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

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>WeatherSocketServer.java </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. WeatherSocketServer.java
  11. 11. WeatherSocketServer.java
  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

×