Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
30 lines (23 loc) · 914 Bytes

File metadata and controls

30 lines (23 loc) · 914 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package network;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class TCPServer {
public static void main(String[] args) throws Exception {
//1. 연결 요청만 담당하는 서버용 socket필요
//prototype(프로토타입) 방법 <-> singleton(싱글톤)
//필요할때마다 객체 생성 <-> 하나만 객체 생성 주소를 재사용
ServerSocket server = new ServerSocket(9100);
System.out.println("TCP 서버 시작됨");
System.out.println("클라이언트의 요청을 기다리는 중..");
int count = 0;
while (true) {
Socket socket = server.accept();
System.out.println(count + "번 클라이언트와의 연결 성공.");
count++;
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println("i am a java programmer!!!");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.