diff --git a/cs654/proj1/KaZaClient.java b/cs654/proj1/KaZaClient.java index e01410e..9c89cea 100644 --- a/cs654/proj1/KaZaClient.java +++ b/cs654/proj1/KaZaClient.java @@ -53,6 +53,19 @@ public class KaZaClient public boolean connected() { return m_connected; } + public void close() + { + if (m_connected) + { + try { + m_os.writeBytes("QUIT\n"); + m_os.close(); + m_socket.close(); + } catch (Exception e) { } + m_connected = false; + } + } + public Vector performSearch(String query) { Vector results = new Vector(); diff --git a/cs654/proj1/KaZaServer.java b/cs654/proj1/KaZaServer.java index e12bf07..71b6338 100644 --- a/cs654/proj1/KaZaServer.java +++ b/cs654/proj1/KaZaServer.java @@ -169,6 +169,18 @@ public class KaZaServer implements Runnable } } } + else if (opCode.equals("QUIT")) + { + /* user is requesting to leave the system */ + synchronized (m_clientData) + { + m_clientData.remove(m_clientIP); + br.close(); + os.close(); + m_socket.close(); + return; + } + } } } catch (Exception e) { } }