MMT1-Lec9 - Computer Networks 1 (Mng My Tnh 1) Lectured by:...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Networks 1 (M ng Máy Tính 1) Lectured by: Nguy n Đứ c Thái
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture 9: Socket Programming with Java
Background image of page 2
Using InetAddress (1) ± Get local address import java.net.*; public class HostInfo { public static void main(String args[]) { HostInfo host = new HostInfo(); host.init(); } public void init() { try { InetAddress myHost = InetAddress.getLocalHost(); System.out.println(myHost.getHostAddress()); System.out.println(myHost.getHostName()); } catch (UnknownHostException ex) { System.err.println("Cannot find local host"); } } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Using InetAddress (2) ± In đị ach IP c a proxy.hcmut.edu.vn import java.net.*; class kku{ public static void main (String args[]) { try { InetAddress[] addresses = InetAddress.getAllByName(“proxy.hcmut.edu.vn"); for (int i = 0; i < addresses.length; i++) { System.out.println(addresses[i]); } } catch (UnknownHostException e) { System.out.println("Could not find proxy.hcmut.edu.vn"); } } }
Background image of page 4
Using Socket (1) ± K ế tn i đ ên 1 s
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

MMT1-Lec9 - Computer Networks 1 (Mng My Tnh 1) Lectured by:...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online