summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDor Bivas <dor1_b@walla.com>2014-01-18 14:52:09 +0200
committerDor Bivas <dor1_b@walla.com>2014-01-18 14:59:23 +0200
commite0bb3dd9dc74c6b0fb8a51c2d2afb398c00768ce (patch)
tree839f689dd96e38ac3768a3fe8e6f68b1bfe871e4 /src
parent2abe19f0946d571a784b93d66a54d5c686313aa5 (diff)
server: Client now know connection
* Client.Disconnect is now using Connection.shutdown command. * Connection knows now client and vice versa.
Diffstat (limited to 'src')
-rw-r--r--src/Server/Client.java13
-rw-r--r--src/Server/Connection.java8
2 files changed, 8 insertions, 13 deletions
diff --git a/src/Server/Client.java b/src/Server/Client.java
index b76bb57..315c363 100644
--- a/src/Server/Client.java
+++ b/src/Server/Client.java
@@ -10,11 +10,13 @@ public class Client
Socket soc;
BufferedWriter output;
ChatServer server;
+ private Connection con;
- public Client(Socket soc, BufferedWriter output)
+ public Client(Socket soc, BufferedWriter output, Connection con)
{
this.soc = soc;
this.output = output;
+ this.con = con;
}
/** returning the nick name */
public String getNick()
@@ -45,14 +47,7 @@ public class Client
/** closing the socket */
public void disconect ()
{
- try {
- this.soc.close();
- }
- catch (IOException e)
- {
- System.err.println("The socket failed to closed: " + e);
- }
-
+ this.con.shutdown();
}
/** prints a line to the client socket
diff --git a/src/Server/Connection.java b/src/Server/Connection.java
index 62afa9a..92869f1 100644
--- a/src/Server/Connection.java
+++ b/src/Server/Connection.java
@@ -11,7 +11,6 @@ class ParsedLine
private String line;
private String command;
private String args;
-
public ParsedLine(String line)
{
@@ -42,18 +41,20 @@ class ParsedLine
public class Connection extends Thread
{
private Socket soc;
+ private Client client;
public Connection(Socket soc)
{
this.soc = soc;
}
- private void shutdown()
+ public void shutdown()
{
try
{
if (!soc.isClosed())
soc.close();
+
} catch (IOException e) {}
}
@@ -67,13 +68,12 @@ public class Connection extends Thread
{
try
{
- Client client;
CommandsTable commandsTable = new CommandsTable();
DataInputStream input = new DataInputStream(soc.getInputStream());
OutputStreamWriter outTemp = new OutputStreamWriter(soc.getOutputStream());
BufferedWriter output = new BufferedWriter(outTemp);
- client = new Client(soc, output);
+ client = new Client(soc, output, this);
while (true)
{