Cute Happy Ghost
본문 바로가기
JAVA/Java

20201019_18

by JENN_tech7 2020. 10. 19.
728x90
SMALL

LAN 인터넷 네트워크

IEEE(아이트리플이) 그것을 만드는 기관

도메인 : www.yahoo.co.kr  등(실직적으로ip주소로 쓰인다)

TCP :패킷빠졌을 때 재전송 요청, 재조합

       TCP는 전송계층이라 세그먼트라 부르지만 패킷을 받았을 때 분실한다면 세그먼트로 못 만듬

       그것을 재조합하면 세그먼트됨

 

실시간 멀티미디어정보 UDP ->RTP(신뢰성x)/RTCP(신뢰성o)

 


 

 

 

 

 

package test01.inet;
import java.net.*;
public class InetAddressEx {
	InetAddress ip = null;
	String ip1 = null;
	//메소드 생성
	public void testInetAddress() throws Exception {
		ip = InetAddress.getLocalHost();
		System.out.println(ip); //로컬 호스트 주소 출력
		ip1 = ip.getHostAddress();
		System.out.println(ip1); //호스트 주소 출력
		
		System.out.println(ip.getHostName());
		System.out.println(ip.getHostAddress());
		System.out.println(ip.toString());
	}
	
	@Override
	public String toString() {
		return "InetAddressEx [ip=" + ip + ", ip1=" + ip1 + "]";
	}

	public static void main (String args[]) throws Exception  {
		InetAddressEx inet = new InetAddressEx();
		inet.testInetAddress();
		System.out.println(inet.toString());
	}
}

Tostring : 설명해주는애

출력결과

user1-PC/192.168.40.23
192.168.40.23
user1-PC
192.168.40.23
user1-PC/192.168.40.23
InetAddressEx [ip=user1-PC/192.168.40.23, ip1=192.168.40.23]

 

 

 

 

 

 

생성자에 넣어서 호출한게아니라 test어쩌구를 호출한거

 

 

 

package test01.inet;
import java.net.*;
public class TestNetAdress {

	public static void main(String[] args) throws UnknownHostException {
		
		InetAddress ip1 = InetAddress.getLocalHost();
		System.out.println(ip1.getHostAddress());
		System.out.println(ip1.getHostName());
		InetAddress ip2 = InetAddress.getByName("www.naver.com");
		
		InetAddress[] ipes = ip2.getAllByName("www.google.com");
		System.out.println("naver : " + ip2.getHostAddress());
		System.out.println("google의 서버는 " + ipes.length + "개 있음");
		
		for (InetAddress ip : ipes) 
			System.out.println(ip.getHostAddress());
		
		InetAddress[] ipes2 = InetAddress.getAllByName("www.naver.com");
		System.out.println("naver의 서버ip는" + ipes2.length + "개 있음");
		
		for(InetAddress ip : ipes2)
			System.out.println(ip.getHostAddress());
	}

}
192.168.40.23
user1-PC
naver : 125.209.222.142
google의 서버는 1개 있음
172.217.161.164
naver의 서버ip는2개 있음
125.209.222.142
210.89.160.88

 

 

저 두개가 같다고한다

for each문 

... 복습각...

모르겠는데요..? ㅋ

 

 

 

 

 

2 (getPort) :-1은 연결되어 있다는 뜻

3 (getHost)

4 (getFile) 파일읽어들이는게 없기때문에

5 (toExternalForm) url전부를 보겠다

 

 

http : 프로토콜

뒤에 : 호스트네임

 

 

 

웹크롤링 : developers.naver.com/docs/search/blog/

 

검색 API 블로그 검색 개발가이드

NAVER Developers - 검색 API 블로그 검색 개발가이드

developers.naver.com

코드드레그해서 그대로 가져와

 

 

 

 

 

 

package test03.tcp;
import java.io.*;
import java.net.*;
public class TCPEchoServer {
	public void tcpServer(int port) {
		// 서버 소켓 관련 객체
		ServerSocket serverSock = null;
		Socket sock = null;
		InetAddress inetAddr = null;
		// 입출력 객체
		InputStream in = null;
		OutputStream out = null;
		BufferedReader br = null;
		PrintWriter wr = null;
		try {
			// 서버 소켓 생성
			serverSock = new ServerSocket(port);
			while (true) {
				// 클라이언트의 접속 대기
				System.out.println("====== 클라이언트 접속 대기 중"+
						"(port:" + serverSock.getLocalPort() + ")=====");
				sock = serverSock.accept();
				// 클라이언트의 접속 요청
				inetAddr = serverSock.getInetAddress();
				System.out.println("클라이언트(" + inetAddr.getHostAddress() + ") 접속");
				// 클라이언트와 통신을 위한 stream 생성
				in = sock.getInputStream();
				out = sock.getOutputStream();
				br = new BufferedReader(new InputStreamReader(in));
				wr = new PrintWriter(new OutputStreamWriter(out));
				String msg = null;
				// 클라이언트와 통신
				while ((msg = br.readLine()) != null) {
					System.out.println("\tCLIENT> " + msg);
					wr.println(msg);
					wr.flush();
				}
			}
		} catch (IOException ie) {
			System.out.println(ie);
		} finally {
			try {
				br.close();
				wr.close();
				in.close();
				out.close();
				sock.close();
				serverSock.close();
				System.out.println("종료.");
			} catch (IOException ie) {
				System.out.println(ie);
			}
		}
	}
}

포트번호로 인식받기

접속들어오면 통신해야지 라고 생각

 

 

serversocket 서버열때 무조건 만들어야됨

socket 실제 연결들어와서 대기

 

outputStreamWriter이랑 printwriter이랑 연결해야지 안정적으로 됨

 

 

 


true = false

반댓값을 넣어줌 : !

package test04;
import java.util.*;
public class HashMapEx1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HashMap map = new HashMap();
		map.put("myId", "1234");
		map.put("hana", "1111");
		map.put("nana", "1234");
		
		Scanner s = new Scanner(System.in);//화면으로부터 라인단위로 입력받음
		while (true) {
			System.out.println("id와 password를 입력해주세요.");
			System.out.print("id :");
			String id = s.nextLine().trim();
			
			System.out.print("password :");
			String password = s.nextLine().trim();
			System.out.println();
			
			if (!map.containsKey(id)) {
				System.out.println("입력하신 id는 존재하지않습니다. 다시 입력해주세요");
				continue;
			}else {
				if (!(map.get(id).equals(password))) {
					System.out.println("비밀번호가 일치하지않습니다. 다시입력해주세요");
				}else {
					System.out.println("id와 비밀번호가 일치합니다");
					break;
				}
			}
			
		}//while
	}//main

}

if (!map.containsKey(id))

if (map.containsKey(id) == true)같은 말

fㄴㅇㄹㅇㄴㅇㄴㄹㄴㅇㅇ

ㅇ런ㅇㄻㄴㄹㄴㅇㄹㄴㅇid

 

 

iterator를 넣으면 모든 것을 출력?

근데 hashmap은 안된다

그럼어떻게 하니?

하나를 거쳐야된다(뭔말인지 모름 ㅠ)ㅋ

entryset을 이용해서 가져옴....

set은 haspmap의 상위맵

중복을 삭제해준다구한다

 

 

 

나는 왜 오류뜨냐고!!

글고 밑에 while저거 뭐징

while (en.hasMoreElements()) {
type type = (type) en.nextElement();

}

이 문법 대체 뭐야 ㅎㅎㅎㅎㅎㅎㅎㅎㅎㅎ

 

 

 

hashset : 중복검색? 

 

package test04;
import java.util.*;
public class HashSetEx {

	public static void main(String[] args) {
		HashSet set = new HashSet();
		set.add(new Person("hanna", 36));
		set.add(new Person("mina", 18));
		System.out.println(set);
	}

}

class Person{
	String name;
	int age;
	Person(String name, int age) {
		this.name = name;
		this.age = age;
	}
	public String toString() {
		return name + " : " + age;
	}
}
[hanna : 36, mina : 18]

 

 

 

 

 

 

입력받아서 출력하게나오기

 

 

 

 

 

 

package test04;
import java.util.*;
public class HashSetEx {

	public static void main(String[] args) {
		HashSet set = new HashSet();
		String str = null;
		int age = 0;
		Scanner scan = new Scanner(System.in);
		
		while(true) {
		System.out.println("메뉴");
		System.out.println("(1) : 입력");
		System.out.println("(2) : 출력");
		System.out.println("(3) : 종료");
		int menu = scan.nextInt();
		if (menu ==1) {
			System.out.println("이름 입력 : " );
			str = scan.next();
			System.out.println("나이 입력 : ");
			age = scan.nextInt();
		}else if (menu ==2) {
			set.add(new Person(str, age));
			set.add(new Person("mina", 18));
			System.out.println(set);
		}else if (menu ==3) {
			System.out.println("종료");
			break;
		}
	}

}
}
class Person{
	String name;
	int age;
	Person(String name, int age) {
		this.name = name;
		this.age = age;
	}
	public String toString() {
		return name + " : " + age;
	}
}
메뉴
(1) : 입력
(2) : 출력
(3) : 종료
1
이름 입력 : 
김
나이 입력 : 
20
메뉴
(1) : 입력
(2) : 출력
(3) : 종료
2
[김 : 20, mina : 18]
메뉴
(1) : 입력
(2) : 출력
(3) : 종료
3
종료

 

내가 만들어 본거

1번 누르면 어쩌구저쩌구 이렇게

728x90
LIST

'JAVA > Java' 카테고리의 다른 글

20201020_19 제네릭, static  (0) 2020.10.20
20201019_18 영업실적프로그램  (0) 2020.10.19
20201016_17 네트워크  (0) 2020.10.16
20201016_17 arraylist, map, 상속  (0) 2020.10.16
20201015_16  (0) 2020.10.15

댓글