오늘은 22의 가호를 받은 날인가바.... 22일차 22년 11월 22일:3c
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();
}
}
}
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();
}
}
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
}
}
}
}
- Web Server (= HTTP Server)
- WAS (Web Application Server)
출처 : https://luckyguystory.tistory.com/23(강사님 블로그)
출처 : https://luckyguystory.tistory.com/23(강사님 블로그)
출처 : https://luckyguystory.tistory.com/23(강사님 블로그)
출처 : https://kyungjinsprogramming.tistory.com/3
어려워요