java ServerSocket.accept not responding



我的代码有问题。serversocket之后的代码不起作用,这意味着一旦到达serversocket.accept。

import java.io.*;
import java.net.*;
public class AppChat {
    String[] list = { 
        "Take me ", 
        "the code", 
        "Hello from the other side", 
        "the man ",
        "what can we do?", 
        "that is all for today" 
        };
    void go() {
        try {
            ServerSocket serverSocket = new ServerSocket(53439);
            boolean t = true;
            while (true) {
                System.out.println("i am about to execute serverSocket");

所有内容都可以到这个位置,但是此后,此代码是库存的.Accept。请,我在做什么错,因为我试图寻找理解,但仍然没有得到正确的答案。

                Socket socs = serverSocket.accept();// everything is stocked here
                System.out.println("unfortunatly the serverSocket.accept is hoding all the goodies");
                PrintWriter wr = new PrintWriter(socs.getOutputStream());
                String advce = getAdvice();
                wr.println(advce);
                wr.close();
                System.out.println(advce);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String getAdvice() {
        int randdon = (int) (Math.random() * list.length);
        // System.out.println(list[randdon]);
        return list[randdon];
    }
    public static void main(String[] args) {
        AppChat app = new AppChat();
        app.go();
        app.getAdvice();
    }
}

ServerSocket#accept()块,直到从客户端获得传入的连接为止。如果没有客户连接,则此行将无限阻止。

最新更新