Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-09-2009, 01:10 PM
Member
 
Join Date: Jan 2009
Posts: 32
Rep Power: 0
ChrisMayhew is on a distinguished road
Default [SOLVED] Chat Application question
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?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-09-2009, 03:29 PM
Member
 
Join Date: Jan 2009
Posts: 32
Rep Power: 0
ChrisMayhew is on a distinguished road
Default
I have kinda figured out what i need to do i think. Within my client server code i created a SCommands(String NxtCmd) and copied all my if (NxtCmd) commands into that. However the CS.GetChannels etc get an error saying:

Quote:
cannot find symbol
symbol: method getUsersOnline()
location: class CS
I assume this is because the code is now above the main or the CS storing the connection to the server isn't accessible to the SCommands() part.
Any idea how i can make the CS available to everything within the code and not just main?

Thanks
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-09-2009, 05:11 PM
Member
 
Join Date: Jan 2009
Posts: 32
Rep Power: 0
ChrisMayhew is on a distinguished road
Default
Just to update, playing about myself I have managed to make CS available to the whole code in the client so I have no separated my main functions like the commands to send to the server and getting the username from the user.

The only thing I am stuck on if anyone can help is making it so that the server will keep asking the user for commands until the issue the command /Quit I have the code to quit already in place but I need it to keep asking the user for commands.

Any help would be great!

Thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-09-2009, 05:40 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,149
Rep Power: 2
CJSLMAN is on a distinguished road
Default while loop?
Place the server's request code in a "while" loop?

Luck,
CJSL
__________________
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-09-2009, 07:23 PM
Member
 
Join Date: Jan 2009
Posts: 32
Rep Power: 0
ChrisMayhew is on a distinguished road
Default
Originally Posted by CJSLMAN View Post
Place the server's request code in a "while" loop?

Luck,
CJSL
That worked perfect Thanks

I don't know why I didn't think of that in the first place.. lol
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-09-2009, 08:44 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,149
Rep Power: 2
CJSLMAN is on a distinguished road
Default Any time...
Welcome...

Luck,
CJSL
__________________
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to implement private chat application using jsp PortalTeam JavaServer Pages (JSP) and JSTL 5 04-22-2009 11:52 AM
Multi Client/Server Chat Question Kodak07 Networking 3 03-29-2009 10:50 PM
SCTP chat rams Networking 0 10-23-2008 09:48 AM
Decentralized chat KamilR Networking 5 05-05-2008 07:27 AM
Help in Chat application zocky Networking 0 11-08-2007 07:19 PM


All times are GMT +2. The time now is 03:07 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org