Index: trunk/24.SocketTest/assets/SocketServer.java =================================================================== --- trunk/24.SocketTest/assets/SocketServer.java (revision 87) +++ trunk/24.SocketTest/assets/SocketServer.java (revision 87) @@ -0,0 +1,76 @@ +import java.net.*; +import java.io.*; + +public class SocketServer extends Thread +{ + private ServerSocket ss; + private Socket s; + private InputStream is; + private OutputStream os; + private DataInputStream dis; + private DataOutputStream dos; + + public SocketServer(){ + try{ + ss = new ServerSocket(5000); + pln("��� ��린以�5000�ы�)...."); + + s = ss.accept(); + pln("Socket �곌껐��� : " + s); + + is = s.getInputStream(); + os = s.getOutputStream(); + dis = new DataInputStream(is); + dos = new DataOutputStream(os); + start(); + + read(); + }catch(Exception e){ + pln("Socket ��������" + e); + }finally{ + closeAll(); + } + } + private void read(){ + String msg = ""; + try{ + while(true){ + msg = dis.readUTF(); + pln("���濡����client Msg : " + msg); + } + }catch(IOException ie){ + pln("硫��吏��쎈� ��� : " +ie); + } + } + + BufferedReader br + = new BufferedReader(new InputStreamReader(System.in));//Data Source + public void run(){ // �곕���� ��� �� + String str = null; + try{ + while((str = br.readLine()) != null){ + dos.writeUTF(str); //dos : Data Destination + dos.flush(); + } + }catch(IOException ie){ + pln("run() : " + ie.toString()); + } + } + private void closeAll(){ + try{ + if(dis != null) dis.close(); + if(dos != null) dos.close(); + if(is != null) is.close(); + if(os != null) os.close(); + if(s != null) s.close(); + if(ss != null) ss.close(); + }catch(IOException ie){} + } + private void pln(String str){ + System.out.println(str); + } + public static void main(String[] args) + { + new SocketServer(); + } +}