Results 1 to 6 of 6
- 01-09-2009, 01:10 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 32
- Rep Power
- 0
[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
Java 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?
- 01-09-2009, 03:29 PM #2
Member
- Join Date
- Jan 2009
- Posts
- 32
- Rep Power
- 0
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:
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.cannot find symbol
symbol: method getUsersOnline()
location: class CS
Any idea how i can make the CS available to everything within the code and not just main?
Thanks
- 01-09-2009, 05:11 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 32
- Rep Power
- 0
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
- 01-09-2009, 05:40 PM #4
while loop?
Place the server's request code in a "while" loop?
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-09-2009, 07:23 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 32
- Rep Power
- 0
- 01-09-2009, 08:44 PM #6
Similar Threads
-
How to implement private chat application using jsp
By PortalTeam in forum JavaServer Pages (JSP) and JSTLReplies: 9Last Post: 02-19-2010, 10:49 PM -
Multi Client/Server Chat Question
By Kodak07 in forum NetworkingReplies: 3Last Post: 03-29-2009, 10:50 PM -
SCTP chat
By rams in forum NetworkingReplies: 0Last Post: 10-23-2008, 09:48 AM -
Decentralized chat
By KamilR in forum NetworkingReplies: 5Last Post: 05-05-2008, 07:27 AM -
Help in Chat application
By zocky in forum NetworkingReplies: 0Last Post: 11-08-2007, 07:19 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks