- 论坛徽章:
- 0
|
客户端- if (socket != null || socket.isConnected()) {
- socket.close();
- System.out.println(socket.isConnected());
- }
复制代码 怎么还打印true
另外服务端怎样知道这个连接断开了呢
不通过发送命令
服务端- public void Close() {
- try {
- this.setFlag(true);
- exec.shutdown();
- server.close(); //如果注释这里就没异常
- } catch (Exception ex) {
- Logger.getLogger(_SocketListen.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
复制代码 不然就出异常 socket.close- private void Listen() throws IOException {
- Socket socket = server.accept(); // 异常指这行
- this.setNum(this.num + 1);
- this.setFlag(false);
- _SocketThread t = ClassManager.get_SocketThread();
- t.setNum(this.num);
- t.setSocket(socket);
- exec.execute(t);
- }
复制代码 |
|