2012-04-16 11 views

答えて

2

ServerSocket serverSocket = new ServerSocket(8000); //8000 - port number 
Socket client = serverSocket.accept(); // thread will wait here till a client connects 

BufferedReader inFromClient = new BufferedReader(
         new InputStreamReader(client.getInputStream())); 
       DataOutputStream outToClient = new DataOutputStream(
         client.getOutputStream()); 
while ((inputLine = inFromClient.readLine()) != null) { 
        System.out.println("Server: " + inputLine); 

        if(inputLine.equals("END")) 
        { 
         outToClient.writeBytes("END\n"); 
        } 
        else 
        { 
         outToClient.writeBytes("Received\n"); 
        } 
       } 
       inFromClient.close(); 
       outToClient.close(); 

そのあなたが処理するために必要なTCPコネクション次サーバーが起動中にスレッドを作成してみませんか

関連する問題