자바-11장N'1-502

Similar documents
13-Java Network Programming

<4D F736F F F696E74202D20C1A63235C0E520B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

PowerPoint Presentation

(Microsoft PowerPoint - AUTCHEYREGRG.ppt [\310\243\310\257 \270\360\265\345])

Microsoft PowerPoint - 04-UDP Programming.ppt

Microsoft PowerPoint - 03-TCP Programming.ppt

TCP.IP.ppt

rmi_박준용_final.PDF

Network seminar.key

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

JMF2_심빈구.PDF

SMB_ICMP_UDP(huichang).PDF

Subnet Address Internet Network G Network Network class B networ

class InetAddress3{ public static void main(string[] args) throws Exception{ String url = null ; Scanner reader = new Scanner(System.in); System.out.p

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

hd1300_k_v1r2_Final_.PDF

학습목표 네트워크개요 TCP PORT URL/InetAddress Socket/TCP 을이용한네트워크 2

6강.hwp

FileMaker ODBC and JDBC Guide

Chap12

1217 WebTrafMon II

02 C h a p t e r Java

FileMaker ODBC and JDBC Guide

<4D F736F F F696E74202D20C1A63234C0E520C0D4C3E2B7C228B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

12-file.key

USB USB DV25 DV25 REC SRN-475S REC SRN-475S LAN POWER LAN POWER Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl C

JAVA PROGRAMMING 실습 09. 예외처리

PowerPoint 프레젠테이션

PWR PWR HDD HDD USB USB Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl Cable PC PC DDNS (

Java

Interstage5 SOAP서비스 설정 가이드

Sena Device Server Serial/IP TM Version

JMF3_심빈구.PDF

Microsoft PowerPoint - java2-lecture7.ppt [호환 모드]

PowerPoint 프레젠테이션

FileMaker ODBC 및 JDBC 가이드

StruxureWare Data Center Expert 7.2.x 의 새 기능 StruxureWare Data Center Expert 7.2.x 릴리스에서 사용할 수 있는 새 기능에 대해 자세히 알아보십시오. 웹 클라이언트 시작 화면: StruxureWare Cen

Microsoft Word doc

FileMaker 15 ODBC 및 JDBC 설명서

Network Programming

mytalk

Microsoft PowerPoint - [EEL2] Lab10.pptx

API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

PowerPoint Presentation

14-Servlet

목차 INDEX JSON? - JSON 개요 - JSONObject - JSONArray 서울시공공데이터 API 살펴보기 - 요청인자살펴보기 - Result Code - 출력값 HttpClient - HttpHelper 클래스작성 - JSONParser 클래스작성 공공

歯NetworkKawuiBawuiBo.PDF

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

PowerPoint 프레젠테이션

파일로입출력하기II - 파일출력클래스중에는데이터를일정한형태로출력하는기능을가지고있다. - PrintWriter와 PrintStream을사용해서원하는형태로출력할수있다. - PrintStream은구버전으로가능하면 PrintWriter 클래스를사용한다. PrintWriter

bn2019_2

Microsoft PowerPoint - Java7.pptx

PowerPoint 프레젠테이션

Cluster management software

제1장 자바 언어 소개

PowerPoint 프레젠테이션

[ 정보 ] 과학고 R&E 결과보고서 Monte Carlo Method 를이용한 고교배정시뮬레이션 연구기간 : ~ 연구책임자 : 강대욱 ( 전남대전자컴퓨터공학부 ) 지도교사 : 최미경 ( 전남과학고정보 컴퓨터과 ) 참여학생 : 박진명 ( 전

교육2 ? 그림

PowerPoint Presentation

歯JavaExceptionHandling.PDF

01-OOPConcepts(2).PDF

10X56_NWG_KOR.indd

Remote UI Guide

Microsoft PowerPoint - RMI.ppt

신림프로그래머_클린코드.key

07 자바의 다양한 클래스.key

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

1. GigE Camera Interface를 위한 최소 PC 사양 CPU : Intel Core 2 Duo, 2.4GHz이상 RAM : 2GB 이상 LANcard : Intel PRO/1000xT 이상 VGA : PCI x 16, VRAM DDR2 RAM 256MB

Network Programming

PowerPoint Presentation

제20회_해킹방지워크샵_(이재석)

Microsoft PowerPoint - ch02_인터넷 이해와 활용.ppt

TTA Verified : HomeGateway :, : (NEtwork Testing Team)

슬라이드 1

개요

시스코 무선랜 설치운영 매뉴얼(AP1200s_v1.1)

Analyze Connection Failover Options.ppt

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

<4D F736F F F696E74202D E20C0CEC5CDB3DD20C0C0BFEB20B9D720BCADBAF1BDBA20B1E2BCFA E >

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

쉽게 풀어쓴 C 프로그래밊

슬라이드 제목 없음

PowerPoint 프레젠테이션

JMF1_심빈구.PDF

1. What is AX1 AX1 Program은 WIZnet 사의 Hardwired TCP/IP Chip인 iinchip 들의성능평가및 Test를위해제작된 Windows 기반의 PC Program이다. AX1은 Internet을통해 iinchip Evaluation

Cluster management software

untitled

UDP Flooding Attack 공격과 방어


MasoJava4_Dongbin.PDF

cam_IG.book

10-Java Applet


<4D F736F F F696E74202D E20B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D62E >

PowerPoint 프레젠테이션

untitled

chapter4

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

슬라이드 1

Transcription:

C h a p t e r 11

java.net.,,., (TCP/IP) (UDP/IP).,. 1 ISO OSI 7 1977 (ISO, International Standards Organization) (OSI, Open Systems Interconnection). 6 1983 X.200. OSI 7 [ 11-1] 7. 1 (Physical Layer), 2 (Data Link Layer), 3 (Network Layer), 4 (Transport Layer), 5 (Session Layer), 6 (Presentation Layer), 7 (Application Layer). 1, 2, 3, 4, 5, 6, 7., ( ) (path),, ( ). 472

2 (Internet) (Network of Networks). TCP/IP UDP/IP. TCP/IP,,. [ 11-2] 4.,,,. OSI 7 1, 2, 3, 4, 5, 6, 7., FDDI,, X.25, IP, ICMP, IGMP, ARP, RARP, TCP, UDP. HTTP, FTP, E-mail, Telnet, SMTP, DNS. (Client & Server) P2P(Peer-to-Peer).,. P2P. 473

[ 11-3]. ( ). (Header). (1+), (2) (1+) (2+1+). ( )., (Encapsulation). ( ). ( ),. (Decapsulation). ( ) ( ). 474

3 (Internet Adress), IP,. IP,. IP IP. IP 4 10.(), 32. 10 0 255, 256 8. 32.,., 211.102.111.012. 475

(Port). ( ),., HTTP (80), FTP (21), Telnet (23), SMTP tjqltm(25), ECHO (7). TCP/IP 16, 1~65,535. 0~1,024, 1025~65,535. (Socket),.,.., MS-Windows 3.1 MS-Windows 98/NT/XP.,.. TCP(Transmission Control Protocol) UDP(User Datagram Protocol), java.net.. [ 11-4]. 476

4 (End Hosts). TCP(Transmission Control Protocol) UDP(User Datagram Protocol). TCP (Connection-Oriented). UDP (Connectionless). 477

5 [ 11-1] java.net. 478

1 [ 11-2]. 2 TCP [ 11-5]. java.net Serversocket. accept( ). 479

accept( ),.. OutputStream( ), InputStream( ).. OutputStream( ), InputStream( ).,.,. TCP [ 11-6]. 480

(TCP/IP) (UDP/IP). ().... < >I love JEJUDO!(client server)< >,! < >I love JEJUDO!(client server)< >., Welcom to connect to TCP Server!(server client).. 481

01 import java.net.; 02 import java.io.; 03 04 class Jv_11_1_TCPServer { 05 public static void main(string args[]) { 06 ServerSocket s1 = null; 07 Socket s2; 08 OutputStream os1; 09 DataOutputStream os2; 10 InputStream is1; 11 DataInputStream is2; 12 13 try { 14 s1 = new ServerSocket(5432); 15 } catch (IOException e) {e.printstacktrace();} 16 while(true) { 17 try { 18 System.out.println("..."); 19 s2 = s1.accept(); 20 System.out.println("!"); 482

21 22 os1 = s2.getoutputstream(); 23 os2 = new DataOutputStream(os1); 24 os2.writeutf("welcom to connect to TCP Server!(server -> client)"); 25 26 is1 = s2.getinputstream(); 27 is2 = new DataInputStream(is1); 28 String st = new String(is2.readUTF()); 29 System.out.println(st); 30 31 is1.close(); 32 is2.close(); 33 os1.close(); 34 os2.close(); 35 s2.close(); 36 } catch(ioexception e) {e.printstacktrace();} 37 } 38 39 } 40 } 483

01 import java.net.; 02 import java.io.; 03 04 class Jv_11_2_TCPClient { 05 public static void main(string args[]) { 06 try { 07 Socket s1; 08 InputStream is1; 09 DataInputStream is2; 10 OutputStream os1; 11 DataOutputStream os2; 484

12 13 String sendstring = "I love JEJUDO!(client -> server)"; 14 s1 = new Socket("127.0.0.1", 5432); 15 is1 = s1.getinputstream(); 16 is2 = new DataInputStream(is1); 17 String st = new String(is2.readUTF()); 18 System.out.println(st); 19 20 os1 = s1.getoutputstream(); 21 os2 = new DataOutputStream(os1); 22 os2.writeutf("< >" + sendstring + "< >"); 23 24 os2.close(); 25 os1.close(); 26 is2.close(); 27 is2.close(); 28 s1.close(); 29 } catch(connectexception connexc) { 30 System.err.println(" "); 31 } 32 catch(ioexception e) {e.printstacktrace();} 33 34 } 35 } 485

486

1 [ 11-3]. 2 UDP [ 11-11]. java.net DatagramSocket, DatagramPacket. TCP accept( ). java.net DatagramSocket, DatagramPacket. 487

send( ), receive( ). send( ), receive( ).. ()... 488

01 import java.net.; 02 import java.io.; 03 import java.lang.; 04 05 public class Jv_11_3_UDPServer { 06 public static void main(string args[]) { 07 try { 08 DatagramSocket ds = new DatagramSocket(9999); 09 byte[] bf = new byte[30]; 10 DatagramPacket dp = new DatagramPacket(bf, bf.length); 11 12 while(true) { 13 try { 489

14 ds.receive(dp); 15 String rs1 = new String(dp.getData()); 16 String rs2 = new String(rs1.trim()); 17 System.out.println(":" + dp.getaddress() + " :" + dp.getport()); 18 System.out.println(" (Client->Server): " + rs2); 19 } catch(ioexception e){} 20 } 21 } catch(ioexception e){} 22 } 23 } 490

01 import java.net.; 02 import java.io.; 03 public class Jv_11_4_UDPClient { 04 public static void main(string args[]) { 05 try { 06 DatagramSocket ds = new DatagramSocket(); 07 InetAddress ia = InetAddress.getByName("localhost"); 08 byte[] bf = args[0].getbytes(); 09 DatagramPacket dp = new DatagramPacket(bf, bf.length, ia, 9999); 10 11 ds.send(dp); 12 13 } catch(exception e){ 14 System.out.println(e); 15 } 16 } 17 } 491

1 InetAddress [ 11-4]. 2 URL [ 11-5], URL [ 11-6]. 492

3 URLConnection [ 11-7], URLConnection [ 11-8]. 493

URL, URLConnection, InetAddress ().., C:\source. 01 import java.net.; 02 03 class Jv_11_5 { 04 public static void main(string args[]) 05 throws Exception, MalformedURLException { 06 URL u = new URL(args[0]); 07 System.out.println("=== URL ==="); 08 System.out.println(":" + u.getprotocol()); 09 System.out.println(": " + u.getport()); 10 System.out.println(": " + u.gethost()); 11 System.out.println("(): " + u.getfile()); 12 System.out.println("URL: " + u.toexternalform()); 13 14 System.out.println("\n=== URLConnection ==="); 494

15 URLConnection uc = u.openconnection(); 16 int len = uc.getcontentlength(); 17 System.out.println(" : " + len + ""); 18 URL uu = uc.geturl(); 19 System.out.println("URL: " + uu); 20 21 System.out.println("\n=== InetAddress ==="); 22 InetAddress addr = null; 23 addr = InetAddress.getByName("www.bu.ac.kr"); 24 System.out.println(" IP"); 25 System.out.println(addr); 26 InetAddress Na[] = InetAddress.getAllByName("www.yonsei.ac.kr"); 27 System.out.println("www.yonsei.ac.kr "); 28 for (int i=0; i<na.length; i++) 29 System.out.println(Na[i]); 30 31 addr = InetAddress.getLocalHost(); 32 System.out.println(" : " + addr.gethostname()); 33 byte ip[] = addr.getaddress(); 34 System.out.println(" IP : "); 35 for (int i=0; i<ip.length; i++) { 36 if ( i > 0) { 37 System.out.print("."); 38 } 39 System.out.print(ip[i] & 0xff); 40 } 41 System.out.println("\n IP : " + addr.gethost Address()); 42 } 43 } 495

496

1 2 3 4 5 6 497

498

1 // file name: Jv_11_b1.java import java.io.; import java.util.; import public class Jv_11_b1 { public static void main(string[] args) { URL u = null; URLConnection uc = null; try { u = new URL("http://www.bu.ac.kr"); uc = } } System.out.println(" : " + uc.getcontenttype()); System.out.println(" : " + + " byte"); System.out.println(" : " + uc.getcontent Encoding ()); System.out.println(" : " + new Date( ); System.out.println(" : " + new Date (uc. getlastmodified())); }catch(malformedurlexception e) { System.out.println(e); }catch(ioexception e) { System.out.println(e); } 499

2 "" // file name: Jv_11_b2.java import java.net.; import java.io.; public class Jv_11_b2 { public static void main(string[] args) { URL u = null; try { u = new URL("http://java.sun.com:80"); }catch(malformedurlexception e) { System.out.println(e); System.exit(0); } System.out.println(" : " + ); System.out.println(" : " + ); System.out.println(" : " + ); System.out.println(" : " + u.getfile()); for(int i=15 ; i<25 ; i++) { try { Socket s = new ("localhost", i); 500

} System.out.println(" :" + i); s.close(); }catch(ioexception e) { System.out.println(" : " + i); } } } 3 501

4 502