스레드 활용 소켓 채팅 프로그램
- 한 쌍의 socket으로 unique한 connection 생성의 이해
- 서버 프로세스에서 client 수 만큼 스레드를 생성하여 connection 생성 및 관리
- Client 1:1 채팅
- Client 1:N 채팅
- Client 로그아웃
- Server에 현재 접속 중인 Client 확인



- 2개 이상의 terminal 실행
- java -jar chatting_program-1.0-SNAPSHOT.jar
- Server 또는 Client 선택
- Server 측 예제
- Server가 먼저 실행되어 listen 상태 유지
> Enter Server or Client
Server
> Enter Port Number (default: 7000):
20:03:09 Server waiting for Clients on port 7000.
- Client 측 예제
- username (default anonymous)
- server port number (default localhost)
- server ip address (default 7000)
> Enter Server or Client
Client
> Enter the username (default: Anonymous):
tester
> Enter Server Port Number (default: 7000):
> Enter the Server Address (default: localhost):
Connection accepted localhost/127.0.0.1:7000
Welcome to the chatroom.Instructions:
1. Simply type the message to send broadcast to all active clients
2. Type '@username message' without quotes to send message to desired client
3. Type 'WHOISIN' without quotes to see list of active clients
4. Type 'LOGOUT' without quotes to logoff from server
> id: 0
> 20:05:44 tester *** tester has joined the chat room. ***
>