자바
고급 자바_0102-2
정재화니
2023. 1. 2. 13:51
클라이언트/서버
- 컴퓨터간의 관계역할로 구분하는 개념
- 서비스를 제공하는 쪽이 서버. 제공받는 쪽이 클라이언트가 된다.
- 제공하는 서비스의 종류에 따라 메일서버, 파일서버, 웹서버 등이 있다.
- 전용서버를 두는 것을 '서버기반 모델' , 전용서버 없이 각 클라이언트가
서버역할까지 동시에 수행하는 것을 'P2P 모델' 이라고 한다.
특징
IP주소
- 컴퓨터(host,호스트)를 구별하는데 사용되는 고유한 주소값
- 4byte의 정수로 'a.b.c.d'와 같은 형식으로 표현.
- IP주소는 네트워크주소와 호스트주소로 구성되어 있다.
InetAddress
- IP주소를 다루기 위한 클래스
URL
- 인터넷에 존재하는 서버들의 자원에 접근할 수 있는 주소.
InetAddress 클래스를 통해서 알아봅니다.
public class InetAddressTest {
public static void main(String[] args) throws UnknownHostException {
// InetAddress 클래스 ==> IP주소를 다루기 위한 클래스
// www.naver.com의 IP정보 가져오기
InetAddress naverIp = InetAddress.getByName("www.naver.com");
System.out.println("HostName : " + naverIp.getHostName());
System.out.println("HostAddress : " + naverIp.getHostAddress());
System.out.println("toString : " + naverIp.toString());
System.out.println();
// 자신의 컴퓨터의 IP정보 가져오기
InetAddress localIp = InetAddress.getLocalHost();
System.out.println("HostName : " + localIp.getHostAddress());
System.out.println("HostAddress : " + localIp.getHostAddress());
System.out.println("toString" + localIp.toString());
System.out.println();
//IP주소가 여러개인 호스트의 정보 가져오기
InetAddress[] naverArr = InetAddress.getAllByName("www.naver.com");
for(InetAddress ip : naverArr) {
System.out.println(ip);
}
}