Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocsf phase2 1 #47

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Test2001.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2002.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2003.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2004.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2005.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2006.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2007.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2008.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2009.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2010.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2011.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2012.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2013.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2014.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Test2017.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 68 additions & 31 deletions code/simplechat1/ClientConsole.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file contains material supporting section 3.7 of the textbook:
// "Object Oriented Software Engineering" and is issued under the open-source
// license found at www.lloseng.com
// license found at www.lloseng.com

import java.io.*;
import client.*;
Expand All @@ -9,74 +9,75 @@
/**
* This class constructs the UI for a chat client. It implements the
* chat interface in order to activate the display() method.
* Warning: Some of the code here is cloned in ServerConsole
* Warning: Some of the code here is cloned in ServerConsole
*
* @author François Bélanger
* @author Dr Timothy C. Lethbridge
* @author Dr Timothy C. Lethbridge
* @author Dr Robert Laganière
* @version July 2000
*/
public class ClientConsole implements ChatIF
public class ClientConsole implements ChatIF
{
//Class variables *************************************************

/**
* The default port to connect on.
*/
final public static int DEFAULT_PORT = 5555;

//Instance variables **********************************************

/**
* The instance of the client that created this ConsoleChat.
*/
ChatClient client;


//Constructors ****************************************************

/**
* Constructs an instance of the ClientConsole UI.
*
* @param host The host to connect to.
* @param port The port to connect on.
* @param port The port to connect on
* @param user The username to connect with.
*/
public ClientConsole(String host, int port)
public ClientConsole(String user, String host, int port)
{
try
try
{
client= new ChatClient(host, port, this);
}
catch(IOException exception)
client= new ChatClient(user, host, port, this);
}
catch(IOException exception)
{
System.out.println("Error: Can't setup connection!"
+ " Terminating client.");
System.exit(1);
System.out.println("Cannot open connection. Awaiting command.");

}
}


//Instance methods ************************************************

/**
* This method waits for input from the console. Once it is
* This method waits for input from the console. Once it is
* received, it sends it to the client's message handler.
*/
public void accept()
public void accept()
{
try
{
BufferedReader fromConsole =
BufferedReader fromConsole =
new BufferedReader(new InputStreamReader(System.in));
String message;

while (true)
while (true)
{
message = fromConsole.readLine();

client.handleMessageFromClientUI(message);
}
}
catch (Exception ex)
}
catch (Exception ex)
{
System.out.println
("Unexpected error while reading from console!");
Expand All @@ -89,33 +90,69 @@ public void accept()
*
* @param message The string to be displayed.
*/
public void display(String message)
public void display(String message)
{
System.out.println("> " + message);
}


protected void connectionClosed() {
System.out.println(" The server is currently shut down.the client quit");
}

public void connectionException(Exception exception) {
System.out.println("WARNING - The server has stopped listening for connections");
}


//Class methods ***************************************************

/**
* This method is responsible for the creation of the Client UI.
*
* @param args[0] The host to connect to.
*/
public static void main(String[] args)
public static void main(String[] args)
{
String user = "";
String host = "";
int port = 0; //The port number

try
{
host = args[0];
user = args[0];

}
catch(ArrayIndexOutOfBoundsException e)
{
System.err.print("ERROR - No login ID specified. Connection aborted.");
System.exit(1);
}

try
{
host = args[1];
}
catch (ArrayIndexOutOfBoundsException e) {

host = "localhost";

}
ClientConsole chat= new ClientConsole(host, DEFAULT_PORT);

try
{
port = Integer.parseInt(args[2]);
}
catch (Throwable t) {

port = DEFAULT_PORT;

}


ClientConsole chat= new ClientConsole(user ,host, port);



chat.accept(); //Wait for console data
}
}
Expand Down
Loading