java network programming problem is not output

In a tone error code, the form has no output port yesterday afternoon. If the output has not, then the possibility of one end of the window has closed relatively large. Because my program is stuck in a loop inside, we can not continue down the implementation. And compare the original code for a long time can not be found. Later found in a place with the if statement with the loop.

while((s=dis.readUTF())!=null){
    System.out.println(s);
    System.out.println("Address:"+s1.getInetAddress());
    System.out.println("port:"+s1.getPort());

}

Because after entering the loop, the only input information Client port and do not enter both cases, it should be added in the inner loop exit conditions. 

 int n = 0;

while((s=dis.readUTF())!=null){
    System.out.println(s);
    System.out.println("Address:"+s1.getInetAddress());
    System.out.println("port:"+s1.getPort());

    n++;

    System.out.println(n);

    if(n==3){
     break;

    }
}

 When a certain number of information transmission, exit the loop. I think if the while statement into the if statement, you can only be performed once, it appears not as flexible while statement.

Guess you like

Origin www.cnblogs.com/hh0326/p/11517813.html