Hello again
Im still working on my chat application, So far i have managed to get it to ask the server for a list of users and a list of channels however I have run into an issue with once a user has done one command say /ShowUsers i made it ask for a second command but it will not show them. I know pretty much why and its because the if statements are above the second command.
So my question is how do i make the client ask for a command and run the if statements then go back to asking for a command... If you get me
I have attached my client code.. I have more than likely made it more complex than it needs to be but im very new to java to be taking on such a project. lol
|
Code:
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.rmi.*;
//import java.rmi.server.RemoteServer;
public class RMIClient {
public static void main(String[] args) {
try
{
RemoteServer CS=(RemoteServer) Naming.lookup("rmi://192.168.1.103/ChatServer");
System.out.println("Please enter a Username: ");
BufferedReader Login = new BufferedReader(new InputStreamReader(System.in));
String LoginName = null;
LoginName = Login.readLine();
InetAddress thisIp = InetAddress.getLocalHost();
String IPAddress = thisIp.getHostAddress();
CS.GetLoginName(LoginName, IPAddress);
System.out.println("Command: ");
BufferedReader Command = new BufferedReader(new InputStreamReader(System.in));
String NxtCmd = null;
NxtCmd = Command.readLine();
if (NxtCmd.equals("/ShowUsers")) {
String [] OnlineUsers = CS.getUsersOnline();
int UOCount = OnlineUsers.length;
int CountUsers = 0;
int UserCount = 0;
while (CountUsers < UOCount) {
if (OnlineUsers[CountUsers] != null) {
UserCount++;
}
CountUsers++;
}
int i = 1;
System.out.println("Username \t Channel");
System.out.println("-------- \t ---------");
while (i <= UserCount) {
String [] temp = null;
temp = OnlineUsers[i].split(";");
//if (OnlineUsers[i] != null ) {
int ChannelI = 1;
int ChannelCount = CS.ChannelCount();
String [] ChatChannels = CS.getChannels();
int[] UserChanNum = CS.getUsersChannels();
String UserChan = null;
while(ChannelI <= ChannelCount) {
if (ChannelI == UserChanNum[ChannelI]) {
UserChan = ChatChannels[ChannelI];
}
ChannelI++;
}
int NameLen = temp[0].length();
if(UserChan == null) {
System.out.println(temp[0] + "\t" + "No Channel");
} else {
System.out.println(temp[0] + "\t" + UserChan);
}
UserChan = null;
//}
i++;
}
} else if (NxtCmd.equals("/ShowChannels")) {
int ChannelI = 1;
int ChannelCount = CS.ChannelCount();
String [] ChatChannels = CS.getChannels();
System.out.println("Channel \t Online");
System.out.println("---------------- ---------");
while (ChannelI <= ChannelCount) {
System.out.println(ChatChannels[ChannelI]);
ChannelI ++;
}
}
System.out.println("Command: ");
NxtCmd = Command.readLine();
}
catch ( Exception e )
{
System.out.println("Exception: " + e.getMessage());
}
}
} |
Any help would be great.
I assume it has to go into its own class or something?