Hi Guys,
I am just learning how to do this so bare with me. I am writing a client/server app that is multithreaded. However, when a single client logs in it works fine. When another client logs in, they then can do whatever they want, but the telnet prompt for the first client is frozen but still remains open. If the second prompt then closes, the first is still frozen. How do I give control to both?
The Client object is threaded so here is the run:
and this is the ListenToClient code... I suspect it has something to do with this while loop...
and for good measure, the TalkToClient Function:
Is it the while loop or is something I am doing with the threads?
Thanks,
Ron
typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
I am just learning how to do this so bare with me. I am writing a client/server app that is multithreaded. However, when a single client logs in it works fine. When another client logs in, they then can do whatever they want, but the telnet prompt for the first client is frozen but still remains open. If the second prompt then closes, the first is still frozen. How do I give control to both?
Code:
[blue]
myClientSocket = myServer.getServerSocket().accept();
ClientCount++;
TalkToClient(myClientSocket,"Enter a name: ");
String mClientName = new String();
try
{
mClientName = ListenToClient(myClientSocket);
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (InterruptedException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
myClient = new Client(myClientSocket,myServer.getStartDate(),mClientName,myServer);
myClient.setName(mClientName);
System.out.println("Added Client to Server: "+myClient.getName());
myClient.start();
[/blue]
The Client object is threaded so here is the run:
Code:
[blue]
public void run()
{
TalkToClient(ServerInfo(),false);
TalkToClient("Logged in...",false);
try
{
ListenToClient();
}
catch (IOException e)
{
}
catch (InterruptedException e)
{
}
}
[/blue]
and this is the ListenToClient code... I suspect it has something to do with this while loop...
Code:
[blue]
public static void ListenToClient() throws IOException, InterruptedException
{
String Input = new String();
while((Input = in.readLine())!=null)
{
TalkToClient(Input,true);
if (Input.equals("exit"))
{
clientSocket.close();
return;
}
} //END WHILE
}//END LISTEN TO CLIENT
[/blue]
and for good measure, the TalkToClient Function:
Code:
[blue]
public static void TalkToClient(String mText, boolean mECHO)
{
StringBuffer myBuffer = new StringBuffer();
if (mECHO) myBuffer.append("Command: "+mText);
else myBuffer.append(SERVER+" - " +VERSION +": "+ mText);
out.println(myBuffer);
}
[/blue]
Is it the while loop or is something I am doing with the threads?
Thanks,
Ron
typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;