diff --git a/.gitignore b/.gitignore
index 537939b80542401d5f9011cd662d0fbe7e7092d1..e9530d2debd9ab8e0f0d9bc59b557b5a768f54e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,42 +1,7 @@
-# See http://help.github.com/ignore-files/ for more about ignoring files.
-
-# compiled output
-# /dist
-/tmp
-/out-tsc
-
-# dependencies
-/node_modules
-
-# IDEs and editors
-/.idea
-.project
+build/
+dist/
+node_modules
+*.class
 .classpath
-.c9/
-*.launch
-.settings/
-*.sublime-workspace
-
-# IDE - VSCode
-.vscode/*
-!.vscode/settings.json
-!.vscode/tasks.json
-!.vscode/launch.json
-!.vscode/extensions.json
-
-# misc
-/.sass-cache
-/connect.lock
-/coverage
-/libpeerconnection.log
-npm-debug.log
-testem.log
-/typings
-
-# e2e
-/e2e/*.js
-/e2e/*.map
-
-# System Files
-.DS_Store
-Thumbs.db
+.project
+.settings
diff --git a/Frontend Angular 4/src/app/shared/components/header/header.component.ts b/Frontend Angular 4/src/app/shared/components/header/header.component.ts
index 44ea333e5d7eb6dcb61b83b97d74dc190933c35c..e99dc7b74f19f6a18912174562d7c44124a15597 100644
--- a/Frontend Angular 4/src/app/shared/components/header/header.component.ts	
+++ b/Frontend Angular 4/src/app/shared/components/header/header.component.ts	
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
 import { Router } from '@angular/router';
 import { AuthenticationService } from '../../services/authentication.service';
 import { SessionService } from '../../services/session.service';
+import { GHCIService } from '../../services/ghci.service';
 import { Usuario } from '../../objects/usuario';
 
 @Component({
@@ -11,7 +12,11 @@ import { Usuario } from '../../objects/usuario';
 })
 export class HeaderComponent implements OnInit {
     usuario: Usuario;
-    constructor(private authService: AuthenticationService, private router : Router, private sessionService : SessionService) {
+    constructor(
+        private authService: AuthenticationService, 
+        private router : Router, 
+        private sessionService : SessionService,
+        private ghciService : GHCIService) {
         this.usuario = authService.getUser();
     }
     ngOnInit() {}
@@ -28,6 +33,7 @@ export class HeaderComponent implements OnInit {
 
     logout(){
         this.sessionService.reset();
+        this.ghciService.desconectarWS();
         this.router.navigate(['/login']);
     }
 }
diff --git a/Frontend Angular 4/src/app/shared/config.ts b/Frontend Angular 4/src/app/shared/config.ts
index 269b0832a942fff97480651e814f48f506bb2fa2..e5b48168ac6ac14bb205b1a53d1043eec5ae2f16 100644
--- a/Frontend Angular 4/src/app/shared/config.ts	
+++ b/Frontend Angular 4/src/app/shared/config.ts	
@@ -1,9 +1,9 @@
 //export const SERVER = 'https://matefun.mybluemix.net';
 //export const GHCI_URL = 'wss://matefun.mybluemix.net/endpoint';
 
-//export const SERVER = 'http://localhost:9090';
-//export const GHCI_URL = 'ws://localhost:9090/endpoint';
+export const SERVER = 'http://localhost:9090';
+export const GHCI_URL = 'ws://localhost:9090/endpoint';
 
 //Configuracion dinamica pensando en servidor con ip dinamica
-export const SERVER = window.location.protocol + '//' + window.location.host;//'http://localhost:9090';
-export const GHCI_URL = window.location.protocol == 'http:'?  'ws://'+window.location.host+'/endpoint': 'wss://'+window.location.host+'/endpoint';
+//export const SERVER = window.location.protocol + '//' + window.location.host;//'http://localhost:9090';
+//export const GHCI_URL = window.location.protocol == 'http:'?  'ws://'+window.location.host+'/endpoint': 'wss://'+window.location.host+'/endpoint';
diff --git a/Frontend Angular 4/src/app/shared/services/authentication.service.ts b/Frontend Angular 4/src/app/shared/services/authentication.service.ts
index 23c2a24b908e3431f000a2762e7ab12403c87218..8967c6f5b671774b1475fb2ee26bbe4d06895c9b 100644
--- a/Frontend Angular 4/src/app/shared/services/authentication.service.ts	
+++ b/Frontend Angular 4/src/app/shared/services/authentication.service.ts	
@@ -33,7 +33,8 @@ export class AuthenticationService {
     }
 
     getToken(){
-        return JSON.parse(sessionStorage.getItem('currentUser')).token;
+        var currentUser = JSON.parse(sessionStorage.getItem('currentUser'));
+        return currentUser? currentUser.token: undefined;
     }
 
     setUserConfig(config){
diff --git a/Frontend Angular 4/src/app/shared/services/ghci.service.ts b/Frontend Angular 4/src/app/shared/services/ghci.service.ts
index 6bb4f0e80cf57fa91a0cca7509215911eab3fcb2..b44656486622a41679781abbc5e978b2d8849407 100644
--- a/Frontend Angular 4/src/app/shared/services/ghci.service.ts	
+++ b/Frontend Angular 4/src/app/shared/services/ghci.service.ts	
@@ -31,9 +31,9 @@ export class GHCIService {
 	private console_error_class : string = "jqconsole-asd";
 
 	consoleBuffer = [];
-	
-	constructor(private authService:AuthenticationService){
 
+	constructor(private authService:AuthenticationService){
+		console.log("contructor ghci");
 		this.conectarWS(GHCI_URL, authService.getUser().cedula, authService.getToken());
 		setInterval( this.checkConnection.bind(this), 5000);	
 		setInterval( this.doPing.bind(this), 30000);	
@@ -84,7 +84,7 @@ export class GHCIService {
 	consoleRef:any;
 
 	conectarWS(wsUrl, cedula, token){
-		if(cedula && !this.connection || this.connection.readyState == WebSocket.CLOSED){
+		if(cedula && token && (!this.connection || this.connection.readyState == WebSocket.CLOSED)){
 			this.connection = new WebSocket(wsUrl+"/"+cedula+"/"+token);
 
 			this.connection.onopen = function(){
@@ -97,6 +97,12 @@ export class GHCIService {
 		}
 	}
 
+	desconectarWS(){
+		if(this.connection){
+			this.connection.close();
+		}
+	}
+
 	logConsole(text){
 		if(this.consoleRef){
 			this.consoleRef.Write(text, 'jqconsole-logs'); 
@@ -157,12 +163,14 @@ export class GHCIService {
 		}
 
 	}
+	
 	resetGutters(){
 		if(this.codemirrorRef!==null){
 			this.codemirrorRef.clearGutter("breakpoints");
 		}
 	}
-		hayWarnings(text){
+	
+	hayWarnings(text){	
 		var line = -1;
 		if(this.waitingForWarning){
 			if(this.waitingForWarning2){
@@ -282,15 +290,18 @@ export class GHCIService {
 	}
 
 	checkConnection(){
-		if(!this.connection || this.connection.readyState == WebSocket.CLOSED){
-			this.conectarWS(GHCI_URL, this.authService.getUser().cedula, this.authService.getToken());
+		var usuario = this.authService.getUser();
+		var token = this.authService.getToken();
+		if(usuario && token && (!this.connection || this.connection.readyState == WebSocket.CLOSED)){
+			this.conectarWS(GHCI_URL, usuario.cedula, token);
 		}		
 	}
 
 	doPing(){
-		if(this.connection && this.connection.readyState == WebSocket.OPEN){
+		var token = this.authService.getToken();
+		if(this.connection && this.connection.readyState == WebSocket.OPEN && token){
 			var message = {
-				'token': this.authService.getToken(),
+				'token': token,
 				'ping': ''
 			};
 			this.connection.send(JSON.stringify(message));
diff --git a/Servidor JEE/src/main/java/edu/proygrado/ejb/CommandsBean.java b/Servidor JEE/src/main/java/edu/proygrado/ejb/CommandsBean.java
index 74bfbfbe8f3fc717f8155c38226a2c9748bc759d..2a36840c07a50b94005837a61158db42f815c472 100644
--- a/Servidor JEE/src/main/java/edu/proygrado/ejb/CommandsBean.java	
+++ b/Servidor JEE/src/main/java/edu/proygrado/ejb/CommandsBean.java	
@@ -1,25 +1,17 @@
 package edu.proygrado.ejb;
 
-import edu.proygrado.dto.ArchivoDTO;
-import edu.proygrado.dto.ConfiguracionDTO;
-import edu.proygrado.modelo.Usuario;
-
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Scanner;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.annotation.PreDestroy;
@@ -29,14 +21,15 @@ import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonArrayBuilder;
 import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
 import javax.json.JsonReader;
 import javax.json.JsonValue;
 import javax.servlet.ServletContext;
-import javax.websocket.SendHandler;
-import javax.websocket.SendResult;
 import javax.websocket.Session;
 
+import edu.proygrado.dto.ArchivoDTO;
+import edu.proygrado.dto.ConfiguracionDTO;
+import edu.proygrado.modelo.Usuario;
+
 @Stateful
 public class CommandsBean {
 
@@ -79,8 +72,6 @@ public class CommandsBean {
 
 	public void ejecutarComandos(String comandos, Session session) {
 		System.out.println("Ejecuto " + this.hashCode());
-		// almaceno la session del websocket para realizar la respuesta
-		// asincrona.
 		try {
 			JsonReader jsonReader = Json.createReader(new StringReader(comandos));
 			JsonObject comandoJson = jsonReader.readObject();
@@ -117,7 +108,7 @@ public class CommandsBean {
 						}
 						String contenido = archivo.getContenido();
 						String fullPathMatefunTmp = context
-								.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp/");
+								.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp")+"/";
 						try {
 
 							File file;
@@ -173,7 +164,7 @@ public class CommandsBean {
 					}
 					String contenido = archivo.getContenido();
 					String fullPathMatefunTmp = context
-							.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp/");
+							.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp")+"/";
 					try {
 
 						File file;
@@ -228,7 +219,7 @@ public class CommandsBean {
 			}
 
 			String fullPathMatefun = context.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFun");
-			String fullPathMatefunTmp = context.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp/");
+			String fullPathMatefunTmp = context.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp")+"/";
 
 			System.out.println(fullPathMatefun);
 			System.out.println(fullPathMatefunTmp);
@@ -277,7 +268,40 @@ public class CommandsBean {
 			Logger.getLogger(CommandsBean.class.getName()).log(Level.SEVERE, null, ex);
 		}
 	}
+	
+	public void eliminarRecursos(String cedula, String token){
+		String fullPathMatefunTmp = context
+				.getRealPath("/WEB-INF/classes/edu/proygrado/binarios/MateFunTmp")+"/";
+		File directory;
+		if (cedula.toLowerCase().equals("invitado")) {
+			directory = new File(fullPathMatefunTmp + this.cedula + "_" + token );
+			invitadoEJB.eliminarRecursos(token);
+		} else {
+			directory = new File(fullPathMatefunTmp + this.cedula);
+		}
+		deleteDirectory(directory);
+		this.proceso.destroy();
+		this.standardConsoleThread.interrupt();
+		this.errorConsoleThread.interrupt();
+	}
 
+	private boolean deleteDirectory(File directory) {
+	    if(directory.exists()){
+	        File[] files = directory.listFiles();
+	        if(null!=files){
+	            for(int i=0; i<files.length; i++) {
+	                if(files[i].isDirectory()) {
+	                    deleteDirectory(files[i]);
+	                }
+	                else {
+	                    files[i].delete();
+	                }
+	            }
+	        }
+	    }
+	    return(directory.delete());
+	}
+	
 	public ProcessBuilder getProcessBuilder() {
 		return this.builder;
 	}
diff --git a/Servidor JEE/src/main/java/edu/proygrado/ejb/InvitadoEJB.java b/Servidor JEE/src/main/java/edu/proygrado/ejb/InvitadoEJB.java
index da24539dcbfdb975700eafa7d9ceb43b72ebd2a7..8b38d9d1198f0ab1d4ff0f8e0f7b2762bd22eae0 100644
--- a/Servidor JEE/src/main/java/edu/proygrado/ejb/InvitadoEJB.java	
+++ b/Servidor JEE/src/main/java/edu/proygrado/ejb/InvitadoEJB.java	
@@ -51,6 +51,10 @@ public class InvitadoEJB {
 		sesiones.put(token,new InvitadoSesion(usuario));
 	}
 	
+	public void eliminarRecursos(String token){
+		sesiones.remove(token);
+	}
+	
 	public List<ArchivoDTO> getArchivosUsuario(String token, String cedula) throws Exception {
 		System.out.println("getArchivosUsuario"+token);
 		InvitadoSesion invitadoSesion = sesiones.getOrDefault(token, null);
@@ -65,9 +69,6 @@ public class InvitadoEJB {
 							"select ar from Alumno al join al.archivos ar where LOWER(al.cedula)=LOWER(:cedula) and ar.eliminado=0")
 					.setParameter("cedula", cedula).getResultList();
 			em.clear();
-//			archivos.stream().forEach((archivo) -> {
-//				em.detach(archivo);
-//			});
 			invitadoSesion.setArchivos(archivos);
 		}
 
@@ -92,9 +93,6 @@ public class InvitadoEJB {
 					.createQuery("select ar from Alumno al join al.archivosCompartidos ar where al.cedula=:cedula")
 					.setParameter("cedula", cedula).getResultList();
 			em.clear();
-			//			archivosCompartidos.stream().forEach((archivo) -> {
-//				em.detach(archivo);
-//			});
 			
 			invitadoSesion.setArchivosCompartidos(archivosCompartidos);
 		}
@@ -105,9 +103,6 @@ public class InvitadoEJB {
 							"select archivos from Grupo g join g.archivos archivos join g.alumnos alumnos where alumnos.cedula =:cedula")
 					.setParameter("cedula", cedula).getResultList();
 			em.clear();
-			//			archivosGrupo.stream().forEach((archivo) -> {
-//				em.detach(archivo);
-//			});
 			invitadoSesion.setArchivosGrupo(archivosGrupo);
 		}
 		List<ArchivoDTO> archivosDTO = new ArrayList<>();
@@ -134,9 +129,6 @@ public class InvitadoEJB {
 							"select ar from Alumno al join al.archivos ar where LOWER(al.cedula)=LOWER(:cedula) and ar.eliminado=0")
 					.setParameter("cedula", archivoDTO.getCedulaCreador()).getResultList();
 			em.clear();
-			//			archivos.stream().forEach((archivo) -> {
-//				em.detach(archivo);
-//			});
 			invitadoSesion.setArchivos(archivos);
 		}
 
@@ -159,7 +151,6 @@ public class InvitadoEJB {
 				if (usuario == null) {
 					throw new Exception("No existe el usuario de cedula " + archivoDTO.getCedulaCreador());
 				}
-//				em.detach(usuario);
 				em.clear();
 
 			}
@@ -194,9 +185,6 @@ public class InvitadoEJB {
 					.createQuery("select ar from Alumno al join al.archivosCompartidos ar where al.cedula=:cedula")
 					.setParameter("cedula", cedula).getResultList();
 			em.clear();
-			//			archivosCompartidos.stream().forEach((archivo) -> {
-//				em.detach(archivo);
-//			});
 			invitadoSesion.setArchivosCompartidos(archivosCompartidos);
 		}
 
@@ -204,7 +192,6 @@ public class InvitadoEJB {
 		if (archivo == null) {
 			throw new Exception("No exite el archivo de id " + archivoId);
 		}
-//		em.detach(archivo);
 		em.clear();
 
 		Archivo copiaExistente = null;
@@ -251,9 +238,6 @@ public class InvitadoEJB {
 					.createQuery(
 							"select ar from Alumno al join al.archivos ar where LOWER(al.cedula)=LOWER(:cedula) and ar.eliminado=0")
 					.setParameter("cedula", archivoDTO.getCedulaCreador()).getResultList();
-//			archivos.stream().forEach((archivo) -> {
-//				em.detach(archivo);
-//			});
 			em.clear();
 			invitadoSesion.setArchivos(archivos);
 		}
diff --git a/Servidor JEE/src/main/java/edu/proygrado/servicios/ghci/WebSocketEndpoint.java b/Servidor JEE/src/main/java/edu/proygrado/servicios/ghci/WebSocketEndpoint.java
index 33070b2ee60f50ede487f9b4dba6265b87da4b40..6da0d50b511196a45bb6da5af05bb40797f89ff7 100644
--- a/Servidor JEE/src/main/java/edu/proygrado/servicios/ghci/WebSocketEndpoint.java	
+++ b/Servidor JEE/src/main/java/edu/proygrado/servicios/ghci/WebSocketEndpoint.java	
@@ -11,6 +11,8 @@ import javax.ejb.Stateful;
 import javax.ejb.Stateless;
 import javax.json.Json;
 import javax.json.JsonObject;
+import javax.websocket.CloseReason;
+import javax.websocket.OnClose;
 import javax.websocket.OnError;
 import javax.websocket.OnMessage;
 import javax.websocket.OnOpen;
@@ -48,6 +50,13 @@ public class WebSocketEndpoint {
 		}
 	}
 
+	@OnClose
+	public void onClose(@PathParam("cedula") String cedula, @PathParam("token") String token, Session session, CloseReason closeReason) {
+		System.out.println("Cerrando la conexión del web socket");
+		commandsBean.eliminarRecursos(cedula, token);
+	}
+	
+	
 	@OnError
 	public void onError(Throwable t) {
 		System.err.println("Error en conexion");