Networking
TCP      connection-based protocol that provides a      reliable flow of data between two computers.      TCP is based on ...
Data transfer     Ordered data transfer     Retransmission of lost packets     Error-free data transfer     Flow control  ...
Java provides the java.net package to performsystem-independent network communication
Networking basics     A computer generally has a single physicalconnection available for the network.
Port       The physical connection is numbered within a range of 0 to65535, called Ports.       Ranges from 0 to 1023 are ...
URL      Uniform Resource Locator      a reference or an address to a resource onInternet.      Two parts:
URL      Resource name contains:           Host name           File name           Port number
What different?     http://vn.yahoo.com:80/index.html     http://vn.yahoo.com/index.html     http://vn.yahoo.com/
URL       Constructors:             URL(String url)             URL(String protocol, String host, String file)            ...
Methods of URL    public String getHost()    public String getFile()    public String getPath()    public final InputStrea...
Methods of InetAddress     public String getHostAddress()     public String getHostName()     public static InetAddress ge...
URLConnection      Abstract class represents the communication linkbetween an application and a URL.      Used to read fro...
URLConnection     Cannot instantiate a URLConnection obj directly.     Create URLConnection obj by methodopenConnection() ...
Socket     one end-point of a two-way communication linkbetween two programs running on the network
Socket    Socket(String host, int port)          UnknowHostException          OIException
Socket    Retrieve the InputStream from the socket    Retrieve the OutputStream from the socket    Read from the InputStre...
ServerSocket        represents the server side.        If the ServerSocket successful in binding to aport, I can then wait...
ServerSocket    Steps:             . Initiate ServerSocket obj             . accept()             . OutputStream          ...
UDP – User Datagram Protocol       sent message, referred to as datagrams, to otherhost
UDP – User Datagram Protocol     Unreliable     Not ordered     Lightweight     No congestion control
UDPTime-sensitive applications often use UDP      VoIp      Online games
DatagramPacket    create a datagram packet.    Constructors:    DatagramPacket(byte[], int)    DatagramPacket(byte[], int,...
DatagramSocket      represents a socket for sending and receivingdatagram packets.      Constructors:      DatagramSocket(...
Methods of DatagramSocket    public void send(DatagramPacket p)    public void receive(DatagramPacket p)
Methods of DatagramPackets    public InetAddress getAddress()    public int getPort()    public byte[] getData()    public...
Upcoming SlideShare
Loading in …5
×

Networking

714 views

Published on

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
714
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Networking

  1. 1. Networking
  2. 2. TCP connection-based protocol that provides a reliable flow of data between two computers. TCP is based on a four-layered model. HTTP, FTP – High level protocol TCP, UDP – Open, maintain connection IP – Transmits packet from one IP add to another IP – Physical equipment such as twisted pair cables
  3. 3. Data transfer Ordered data transfer Retransmission of lost packets Error-free data transfer Flow control Congestion control
  4. 4. Java provides the java.net package to performsystem-independent network communication
  5. 5. Networking basics A computer generally has a single physicalconnection available for the network.
  6. 6. Port The physical connection is numbered within a range of 0 to65535, called Ports. Ranges from 0 to 1023 are reserved for HTTP, FTP … Data transmitted is accompanied with the destinationaddress and the port number.
  7. 7. URL Uniform Resource Locator a reference or an address to a resource onInternet. Two parts:
  8. 8. URL Resource name contains: Host name File name Port number
  9. 9. What different? http://vn.yahoo.com:80/index.html http://vn.yahoo.com/index.html http://vn.yahoo.com/
  10. 10. URL Constructors: URL(String url) URL(String protocol, String host, String file) URL(String protocol, String host, int port,String file) URL(URL baseURL, String relativeURL)
  11. 11. Methods of URL public String getHost() public String getFile() public String getPath() public final InputStream openStream()
  12. 12. Methods of InetAddress public String getHostAddress() public String getHostName() public static InetAddress getLocalHost() public static InetAddress getByName(String host)
  13. 13. URLConnection Abstract class represents the communication linkbetween an application and a URL. Used to read from and to write to the resourcereferenced by the URL.
  14. 14. URLConnection Cannot instantiate a URLConnection obj directly. Create URLConnection obj by methodopenConnection() of URL class . openConnection() . getInputStream() . getOutStream()
  15. 15. Socket one end-point of a two-way communication linkbetween two programs running on the network
  16. 16. Socket Socket(String host, int port) UnknowHostException OIException
  17. 17. Socket Retrieve the InputStream from the socket Retrieve the OutputStream from the socket Read from the InputStream Write the OutputStream
  18. 18. ServerSocket represents the server side. If the ServerSocket successful in binding to aport, I can then wait and listen for client request public ServerSocket(int port) throws IOException
  19. 19. ServerSocket Steps: . Initiate ServerSocket obj . accept() . OutputStream . InputStream
  20. 20. UDP – User Datagram Protocol sent message, referred to as datagrams, to otherhost
  21. 21. UDP – User Datagram Protocol Unreliable Not ordered Lightweight No congestion control
  22. 22. UDPTime-sensitive applications often use UDP VoIp Online games
  23. 23. DatagramPacket create a datagram packet. Constructors: DatagramPacket(byte[], int) DatagramPacket(byte[], int, InetAddress, int) buf, length, address, port
  24. 24. DatagramSocket represents a socket for sending and receivingdatagram packets. Constructors: DatagramSocket(int) DatagramSocket(port, InetAddress)
  25. 25. Methods of DatagramSocket public void send(DatagramPacket p) public void receive(DatagramPacket p)
  26. 26. Methods of DatagramPackets public InetAddress getAddress() public int getPort() public byte[] getData() public void setData(byte[] data) public void setPort(int port)

×