336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
class RecvThread extends Thread {
Socket s;
public RecvThread(Socket s) {
this.s = s;
}
@Override
public void run() {
// 받는 부분
BufferedReader is;
try {
is = new BufferedReader(new InputStreamReader(s.getInputStream()));
String recvMsg;
while ((recvMsg = is.readLine()) != null) {
System.out.println(recvMsg);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class SendThread extends Thread {
Socket s;
public SendThread(Socket s) {
this.s = s;
}
@Override
public void run() {
PrintWriter os;
try {
os = new PrintWriter(s.getOutputStream(), true);
// 보내는 부분
Scanner sc = new Scanner(System.in);
while (true) {
String msg = sc.next();
os.println(msg);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class ClientTest {
public static void main(String[] args) {
try {
Socket s = new Socket("115.20.247.142", 4000);
SendThread st = new SendThread(s);
RecvThread rt = new RecvThread(s);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}