JAVA 22일차(221122)

점햠미·2022년 11월 22일
0

JATBAP'S JAVA

목록 보기
22/22
post-thumbnail

오늘은 22의 가호를 받은 날인가바.... 22일차 22년 11월 22일:3c

1. 1:1 채팅을 짜시오.

서버

import java.net.*;

public class TcpServer {
   public static void main(String[] args) {
      ServerSocket serverSocket = null;
      Socket socket = null;
      
      try {
         serverSocket = new ServerSocket(7777);
         socket = serverSocket.accept();
         
         Sender sender = new Sender(socket);
         Receiver receiver = new Receiver(socket);
         
         sender.start();
         receiver.start();         
         
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

클라이언트

import java.net.*;

public class TcpClient {
	public static void main(String[] args) {

		String serverIP = "127.0.0.1";		// 자신
		

		try {
			Socket socket = new Socket(serverIP,7777);

			System.out.println("서버에 연결되었습니다.");

			Sender sender = new Sender(socket);
			Receiver receiver = new Receiver(socket);

			sender.start();
			receiver.start();         

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Sender

import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Sender extends Thread {
	Socket socket;
	DataOutputStream out;
	String name;

	public Sender(Socket socket) {
		try {
			out = new DataOutputStream(socket.getOutputStream());
			name = "["+socket.getInetAddress()+":"+socket.getPort()+"]";	
		} catch (Exception e) {
			
		}
	}

	@Override
	public void run() {
		Scanner scanner = new Scanner(System.in);
		while(out != null) {
			try {
				out.writeUTF(name + scanner.nextLine());
			} catch (Exception e) {
				
			}
		}
		scanner.close();
	}
}

Receiver

import java.io.*;
import java.net.Socket;

public class Receiver extends Thread {
	Socket socket;
	DataInputStream in;

	public Receiver(Socket socket) {
		try {
			in = new DataInputStream(socket.getInputStream());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	@Override
	public void run() {

		while(in != null) {
			try {
				System.out.println(in.readUTF());
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
	}
}

2. 아래의 용어에 대하여 설명하시오.

- Web Server (= HTTP Server)
- WAS (Web Application Server)


출처 : https://luckyguystory.tistory.com/23(강사님 블로그)

3.Port Number (포트 번호) 란?


출처 : https://luckyguystory.tistory.com/23(강사님 블로그)

4. 프로토콜(Protocol)이란 무엇이며,프로토콜의 종류는?


출처 : https://luckyguystory.tistory.com/23(강사님 블로그)

5.웹서버 종류는?





출처 : https://kyungjinsprogramming.tistory.com/3

어려워요

profile
인생 망함 개조빱임

0개의 댓글