There are applications for flash AS3 client - socket - Java EJB module on GlassFish server.
If the connection with one or several clients is active and I do undeploying this EJB module, the connections somehow fail badly and the server port remains open. And I don’t like this situation because the port remains busy until the restart of GlassFish or the entire virtual machine.
Well, the question is, of course, how to forcibly close all ports and sockets when the module is minimized?
I don't even know which piece of code to post, well, for example:
in EJB class:
@PreRemove @PreDestroy @PostRemove private void Destroy() throws InterruptedException{ Server.stopServer(); }
In class Server
public static void stopServer(){ IsActiveS = false; for(Server e : Connections){ e.drop(); } try { if(SeSocket!=null){ if(!SeSocket.isClosed()) SeSocket.close(); SeSocket = null; } } catch (IOException ex) { if(Settings.DEBUG)System.out.println("Error occured while closing socket: " + ex.getMessage()); } }
if the variable IsActiveS = false, then all the cycles that are in the class are completed
Connections - list of active connections
IsActive is the same as IsActiveS for only one instance of the connection.
public void drop(){ isActive = false; try { if(socket!=null){ socket.shutdownInput(); socket.shutdownOutput(); socket.setSoTimeout(1); socket.close(); } } catch (IOException ex) {} if(outStreamWriter!=null){ try{ outStreamWriter.close(); }catch (Exception ex){} outStreamWriter = null; } if(inStreamReader!=null){ try{ inStreamReader.close(); }catch (Exception ex){} inStreamReader = null; } if(socket!=null)socket = null; Connections.remove(this); }