From a896509598c5ee5cdfcefb187cb2a2221711e99b Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 9 Mar 2008 00:05:09 +0000 Subject: [PATCH] implemented QUIT message git-svn-id: svn://anubis/gvsu@46 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs654/proj1/KaZaClient.java | 13 +++++++++++++ cs654/proj1/KaZaServer.java | 12 ++++++++++++ 2 files changed, 25 insertions(+) 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) { } }