2013-02-07 2 views
0

오픈 소셜 컨테이너가 있고 해당 컨테이너에 애플릿을 넣어야합니다. 애플릿은 tcpServer로 작동해야합니다. 어떻게해야합니까?TCP 서버 애플릿

+0

기본적으로 내가 어떻게 자바 TCP 서버 애플릿을 설계하는 일부 guidence의 지운이 필요합니다 여기

그것의 요점이다 –

답변

0

networking tutorial은 TCP 서버 소켓을 만들고 그것을 사용하는 방법을 자세히 설명합니다.

ServerSocket serverSocket = null; 
    try { 
     serverSocket = new ServerSocket(4444); 
    } catch (IOException e) { 
     System.err.println("Could not listen on port: 4444."); 
     System.exit(1); 
    } 

    Socket clientSocket = null; 
    try { 
     clientSocket = serverSocket.accept(); 
    } catch (IOException e) { 
     System.err.println("Accept failed."); 
     System.exit(1); 
    } 

    // now get the input and output streams from the client socket 
    // and use them to read and write to the TCP connection 

    clientSocket.close(); 
    serverSocket.close();