server client socket programming output difficulties
<p>m new in socket programming...i hv to create a server that stores name &amp; id from a client in a queue and then it stores all the inputs given by the client in another queue.  when the client writes 'test', server retrieves all the stored data as the client types some value i.e. integer...when client types 'resume' server again starts storing client's given input in the queue...if client types 'exit' server sends back the client's name and id and starts waiting for a ne client. And the receives those info and closes the socket.</p>

<p><strong>Problem faced:</strong>
m facing problem in retrieving the data from queues. when i type exit, i can see the name and id which i'm retriving through the for loop. if i put this line outToClient.writeBytes("Thank You!"+'\n'); after the for loop then it shows the client's name &amp; id but the client doest go off.</p>

<p>in the if else condition while checking for 'test' again i'm facing problem in retrieving data. server asks for integer..client types an integer and then i dont get the data from server.</p>

<p><strong>here is my code</strong></p>

<p><strong>Server Side:</strong></p>

<pre><code>import java.io.*;
import java.net.*;
import java.util.*;

class server
{
  public static void main(String argv[]) throws Exception
{
 String clientSentence;
 String replySentence;
 ServerSocket welcomeSocket= new ServerSocket(6789);

while(true)
{
System.out.println("#########Server Waiting#########");
Socket connectionSocket = welcomeSocket.accept();

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));          
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());

Queue&lt;String&gt; qe = new LinkedList&lt;String&gt;();

outToClient.writeBytes("Enter your Name and ID Please..."+'\n');
for(int i=0;i&lt;=1;i++)
{
 clientSentence = inFromClient.readLine();
 qe.add(clientSentence); 
}

outToClient.writeBytes("Thank you! You may now proceed further..."+'\n'); 

Queue&lt;String&gt; chatq = new LinkedList&lt;String&gt;();
clientSentence = inFromClient.readLine();

while(!clientSentence.equals("exit"))
{

  if(clientSentence.equals("test"))
  {
    outToClient.writeBytes("Enter Integers to fetch data or 'resume' to continue..."+'\n');
    clientSentence = inFromClient.readLine();

    while(!clientSentence.equals("resume"))
    {
        replySentence = chatq.remove();
        outToClient.writeBytes(replySentence+'\n');
        clientSentence = inFromClient.readLine();
    }

    if(clientSentence.equals("resume"))
    {
      outToClient.writeBytes("You may now proceed again..."+'\n');
      clientSentence = inFromClient.readLine();

    } 
  }

  else
  {
    chatq.add(clientSentence);
    clientSentence = inFromClient.readLine();
  }        

}

if(clientSentence.equals("exit"))
{
  outToClient.writeBytes("Client Name &amp; ID: "+'\n');

 for(int i=0;i&lt;=1;i++)
  {
    replySentence = qe.remove();
    outToClient.writeBytes(replySentence+'\n');
  } 


}  
} 
}
}
</code></pre>

<p><strong>Client Side:</strong></p>

<pre><code>import java.io.*;
import java.net.*;
import java.util.*;

class client
{
   public static void main(String argv[]) throws Exception
   {
   String sentence;
   String modifiedSentence;

   BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

   InetAddress inetAddress=InetAddress.getLocalHost();
   System.out.println(inetAddress);

   Socket clientSocket = new Socket(inetAddress,6789);
   while(true)
   {

      DataOutputStream outToServer =  new DataOutputStream(clientSocket.getOutputStream());       

      BufferedReader inFromServer = new  BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

      modifiedSentence=inFromServer.readLine();
      System.out.println("From Server: "+modifiedSentence+'\n');

      for(int i=0;i&lt;=1;i++)
      {
       sentence = inFromUser.readLine();
        outToServer.writeBytes(sentence+'\n');   
      }
       modifiedSentence=inFromServer.readLine();
       System.out.println("From Server: "+modifiedSentence + '\n');



        sentence = inFromUser.readLine();
         while(!sentence.equals("exit"))
         {

if(sentence.equals("test"))
{
  outToServer.writeBytes(sentence+'\n');
  modifiedSentence=inFromServer.readLine();
  System.out.println("From Server: "+modifiedSentence + '\n');
  sentence = inFromUser.readLine();

  while(!sentence.equals("resume"))
  {
    outToServer.writeBytes(sentence+'\n');
    modifiedSentence=inFromServer.readLine();
    System.out.println("From Server: "+modifiedSentence + '\n');
    sentence = inFromUser.readLine();
  }

  if(sentence.equals("resume"))
  {
    outToServer.writeBytes(sentence+'\n');
    modifiedSentence=inFromServer.readLine();
    System.out.println("From Server: "+modifiedSentence + '\n');
    sentence = inFromUser.readLine();

  }

}

else
{
  outToServer.writeBytes(sentence+'\n');
  sentence = inFromUser.readLine();
 }
}

  if(sentence.equals("exit"))
  {
  outToServer.writeBytes(sentence+'\n');
  modifiedSentence=inFromServer.readLine();
  System.out.println("From Server: "+modifiedSentence + '\n');
  for(int i=0;i&lt;=1;i++)
  {
    modifiedSentence=inFromServer.readLine();
    System.out.println(modifiedSentence + '\n');
  } 

  clientSocket.close(); 
  break;
}

}

}
}
</code></pre>
