이 블로그의 인기 게시물
ajax통신, js로 json데이터 가공해서 테이블 만들기
단체 채팅 구현
import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.LinkedList; import java.util.List; public class Server { static List<DataOutputStream> outs; public static void main(String[] args) { try { ServerSocket serverSocket = new ServerSocket(2400); outs = new LinkedList(); Socket socket; DataOutputStream out; while (true) { socket = serverSocket.accept(); new Broadcaster(new DataInputStream(socket.getInputStream()), out = new DataOutputStream(socket.getOutputStream())).start(); outs.add(out); } } catch (Exception e) { e.printStackTrace(); } } static class Broadcaster extends Thread { DataInputStream in; DataOutputStream out; Broadcaster(DataInputStream in, DataOutputStream out) { this.in = in; this.out = out; } @Override public void run() { while (true) { try { String message = in.readUTF(); for (DataOutputStream ou...
댓글
댓글 쓰기