1 / 24

13. 다중전송 소켓

13. 다중전송 소켓. 컴퓨터 네트워크 실험실 이 희 규 , 조 한 진. 목 차. 다중전송 인터넷상에서의 다중전송 다중전송 주소와 다중전송 그룹 라우터와 라우팅 다중전송 소켓 작업 생성자 메소드 MulticastSniffer MulticastSender 결론. 다중전송. 하나의 호스트에서 다중전송 그룹에 가입한 다른 호스트들에게 데이터를 전송하는 것. 인터넷상에서의 다중전송. 캠퍼스. 세상. 0. 1. 4. 3. 2. 5. 4. 1. 0. 3. 2. 1. 3. 2.

Download Presentation

13. 다중전송 소켓

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 13. 다중전송 소켓 컴퓨터 네트워크 실험실 이 희 규, 조 한 진

  2. 목 차 • 다중전송 • 인터넷상에서의 다중전송 • 다중전송 주소와 다중전송 그룹 • 라우터와 라우팅 • 다중전송 소켓 작업 • 생성자 • 메소드 • MulticastSniffer • MulticastSender • 결론

  3. 다중전송 • 하나의 호스트에서 다중전송 그룹에 가입한 다른 호스트들에게 데이터를 전송하는 것

  4. 인터넷상에서의 다중전송 캠퍼스 세상 0 1 4 3 2 5 4 1 0 3 2 1 3 2 4 3 2 1 2

  5. 1 1 1 0 multicast address(28bits) 다중전송 주소와 다중전송 그룹 • 다중전송 주소 • 다중전송 주소는 224.0.0.0 – 239.255.255.255 사이의 IP 주소 사용 • 주소의 첫번째 4비트로 1110을 갖는 클래스 D로 주소 • 다중전송 주소도 호스트 이름을 가질 수 있음

  6. 다중전송 주소와 다중전송 그룹 • 다중전송 그룹 • 다중전송 주소를 공유하는 인터넷 호스트들의 집단 • 다중전송 그룹의 가입과 탈퇴는 자유 • 그룹은 일시적일 수도 있고, 영구한 것일 수도 있음 • 현재 자바는 다중전송 그룹을 만들 수 있는 기능이 없지만, 그룹에 가입할 수 있는 클래스 제공 • IANA(Internet Assigned Number Authority)에서 필요한 경우 영구 다중전송 주소 배부

  7. 라우터와 라우팅 다중전송 소켓을 이용함 다중전송 소켓을 이용하지 않음 클라이언트 라우터 인터넷 라우터 서버

  8. 다중전송 소켓 작업 • MulticastSocket() 생성자를 이용해 객체 생성 • MulticastSocket의 joinGroup() 메소드를 사용하여 다중전송 그룹 가입 • DatagramSocket의 receive() 메소드를 호출을 통한 데이터 수신 • MulticastSocket의 leaveGroup() 메소드를을 호출하여 다중전송 그룹 탈퇴 • java.net.DatagramSocket의 close() 메소드를 사용하여 소켓 종료

  9. 생성자 (1/4) • public MulticastSocket() throws SocketException • 익명 포트에 바인드(bind)되는 소켓을 생성. • java.net.DatagramSocket의 getLocalPort()을 통해 포트 번호 획득. • 소켓 생성 불가능 시에 SocketException 발생

  10. 생성자 (2/4) import java.io.*; import sun.net.*; import java.net.*; publicclass MulticastConstructor { publicstaticvoid main(String[] args) { try { MulticastSocket ms = new MulticastSocket(); System.out.println(ms); } catch (SocketException se) { System.err.println(se); } catch (IOException ioe) { System.err.println(ioe); } } }

  11. 생성자 (3/4) • public MulticastSocket(int port) throws SocketException • 잘 알려진 포트로 데이터 그램을 수신하는 소켓 생성 • 1 – 1023 포트에 바인드시 시스템 루트권한 필요 • 소켓 생성 불가능 시에 SocketException 발생

  12. 생성자 (4/4) import java.io.*; import sun.net.*; import java.net.*; publicclass MulticastPortConstructor { publicstaticvoid main(String[] args) { try { MulticastSocket ms = new MulticastSocket(2048); System.out.println(ms); } catch (SocketException se) { System.err.println(se); } catch (IOException ioe) { System.err.println(ioe); } } }

  13. 메소드 (1/7) • public void joinGroup(InetAddress mcastaddr) throws SocketException • MulticastSocket로부터 데이터를 받기 위해, 다중전송 그룹에 가입 • 다중전송 주소가 아니면(224.0.0.0 – 239.255.255.255) SocketException을 발생(자바 1.1에서는 IOException)

  14. 메소드 (2/7) • public void leaveGroup(Inetaddress mcastaddr) throws SocketException • 다중전송 그룹으로부터 더 이상 데이터그램을 받지 않을 것임을 알림 • 다중전송 주소가 아니면(224.0.0.0 – 239.255.255.255) SocketException을 발생(자바 1.1에서는 IOException)

  15. 메소드 (3/7) • public synchronized void send(DatagramPacket dp, byte ttl) throws IOException, SocketException • 데이터를 DatagramPacket의 객체 dp에 채워 넣고, 이것을 전달 • TTL은 패킷의 이동 공간을 제한하기 위해서 사용

  16. 메소드 (4/7) • 미 대륙에서 만들어진 테이터그램을 기준으로 했을 때 TTL 추정치

  17. 메소드 (5/7) • public void setInterface(InetAddress interface) throws SocketException(자바 1.1에서만) • 멀티 홈 호스트에서, 다중전송을 위해서 사용될 네트워크 인터페이스 선택 • InetAddress가 로컬 기계상의 네트워크 인터페이스가 아니면 SocketException 발생

  18. 메소드 (6/7) import sun.net.*; import java.net.*; import java.io.IOException; publicclass SetInterface{ publicstaticvoid main(String[] args) { MulticastSocket ms; InetAddress ia; try { ia = InetAddress.getByName("kiss.hannam.ac.kr"); ms = new MulticastSocket(2048); ms.setInterface(ia); System.out.println(ms); } catch (UnknownHostException ue) { System.err.println(ue); } catch (SocketException ue) { System.err.println(ue); } catch (IOException ue) { System.err.println(ue); } } }

  19. 메소드 (7/7) • public InetAddress getInterface() throws SocketException • 사용중인 네트워크 인터페이스의 주소를 알고 싶을 때 사용 try { ms = new MulticastSocket(2048); ia =ms.getInterface(); } catch (SocketException se) { System.err.println(se); }

  20. MulticastSniffer (1/2) import sun.net.*; import java.net.*; import java.io.*; publicclass MulticastSniffer { publicstaticvoid main(String[] args) { InetAddress ia = null; byte[] buffer = newbyte[65509]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); int port = 0; try { try { ia = InetAddress.getByName(args[0]); } catch (UnknownHostException e) { // ia = InetAddressFactory.newInetAddress(args[0]); ia = InetAddress.getByName(args[0]); } port = Integer.parseInt(args[1]); } // end try

  21. MulticastSniffer (2/2) catch (Exception e) { System.err.println(e); System.err.println("Usage: java MulticastSniffer MulticastAddress port"); System.exit(1); } try { MulticastSocket ms = new MulticastSocket(port); ms.joinGroup(ia); while (true) { ms.receive(dp); String s = new String(dp.getData(), 0, 0, dp.getLength()); System.out.println(s); } } catch (SocketException se) { System.err.println(se); } catch (IOException ie) { System.err.println(ie); } } }

  22. MulticastSender (1/2) import java.net.*; import java.io.*; import sun.net.*; publicclass MulticastSender { publicstaticvoid main(String[] args) { InetAddress ia = null; int port = 0; String characters = "Here's some multicast data\n"; byte[] data = newbyte[characters.length()]; // read the address from the command line try { try { ia = InetAddress.getByName(args[0]); } catch (UnknownHostException e) { / ia = InetAddressFactory.newInetAddress(args[0]); ia = InetAddress.getByName(args[0]); } port = Integer.parseInt(args[1]); }

  23. MulticastSender (2/2) catch (Exception e) { System.err.println(e); System.err.println("Usage: java MulticastSender MulticastAddress port"); System.exit(1); } characters.getBytes(0, characters.length(), data, 0); DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); try { MulticastSocket ms = new MulticastSocket(); ms.joinGroup(ia); for (int i = 1; i < 10; i++) { ms.send(dp, (byte) 1); } ms.leaveGroup(ia); ms.close(); } catch (SocketException se) { System.err.println(se); } catch (IOException ie) { System.err.println(ie); } } }

  24. 결론 • 다중전송을 하기 위해서는 다중전송 라우터가 반드시 필요하지만 흔하지 않음 • 자바는 다중전송 그룹을 만들 수 있는 기능이 없음.

More Related