Java Server关闭代码

时间:2015-11-18 21:48:15

标签: java sockets

所以我正在制作一个程序来实现一些跨服务器协议。但是,我们必须编辑自己的服务器对象以覆盖某些服务器方法。其中之一就是“近距离”方法。

现在我明白所有的ServerSockets和Sockets都应该调用它们的close()方法,并且我已经通过另一个套接字数组循环,调用所有相应的close()方法。

然而,在运行时,我的程序似乎没有关闭。在终端窗口中,它只保留一个空行,而不是将控制权返回到正常的shell。

我不确定为什么会发生这种情况,我只能断定我的代码有问题?任何帮助都会非常感激(我附上了代码以使我的问题更加清晰)。

服务器的Close方法:

@Override
public void close() throws IOException {
    if (lastSS != null) {
        lastSS.close();
    }
    if (nextSS != null) {
        nextSS.close(); 
    }
    if (acceptSS != null) {
        acceptSS.close();
    }
    if (baseSS != null) {
        baseSS.close();
    }
    if (returnSock != null) { 
        returnSock.close();   
    }
    if (baseGetSock != null) {
        baseGetSock.close();
    }
    if (commSocks != null) {
        for (int i=0; i<commSocks.length; i++) {
            if (commSocks[i] != null) {
            commSocks[i].close();
            }
        }
    }
    super.close();

实际调用server.close():

    try{
       //Some code here
    } catch (IOException e) {
        System.err.println(e);
        e.printStackTrace(System.err);
    } finally {
        server.close();
    }

0 个答案:

没有答案