Hi, ok heres what i am trying to do. I am trying to introduce an array of strings in the Server program to store up to 10 messages, which i think ive got done. If the array is full it should display a full buffer message. Then when the user types in 'READ' it should empty the mail box and display all the messages recieved from the server.

The problem i am having is i cannot get the read to work, im kind of new to java. Any one any ideas? Heres the code:-

//Server class
import java.io.*; 
import java.net.*; 



class TCPPacketServer { 

  public static void main(String argv[]) throws Exception 
          
  { 
      String clientSentence; 
      String capitalizedSentence; 
      Packet  packet;

     System.out.println("Opening port...\n");
      ServerSocket welcomeSocket = new ServerSocket(1025); 
  
       int i=0; String [] Message = new String [10];
       
            Socket connectionSocket = welcomeSocket.accept(); 

	   
           ObjectOutputStream outToClient = new ObjectOutputStream(connectionSocket.getOutputStream());
           ObjectInputStream inFromClient =  new ObjectInputStream(connectionSocket.getInputStream());

try{

     
       //clientSentence 
  while(( packet  = (Packet)inFromClient.readObject())!=null) { 

	 
 
          int x = packet.getSerialNo();
          
	  Integer myx = new Integer(x);
          String str = myx.toString();
           System.out.println("Recieving From Client Packet's serialNo#" + str +" \n and packet's Data is " + packet.getData());
           outToClient.writeObject(str); 
        
       if (i >=10) {
           System.out.println("Full Buffer");
           
       }
       
       else 
       {
           Message[i] = packet.getData();
           i++;
       }
                   
            if (packet.getData().equals("READ"))
            {
		outToClient.writeObject(Message);
               for ( int a=0; a<10; i++)
               {
                    Message[a] ="";
               }
            }
       
           if (packet.getData().equals("CLOSE"))
               break;
  }
           
        
} catch(IOException e)
  {} 
        connectionSocket.close();
    } 
}

//Client
import java.io.*; 
import java.net.*; 
class TCPPacketClient { 

    public static void main(String argv[]) throws Exception 
    { 
        String sentence; 
        String modifiedSentence; 
        int i=1;
        String str="";
	 
        Socket clientSocket = new Socket("LUKESTIRK",1025); 

	
        ObjectInputStream inFromServer = new ObjectInputStream(clientSocket.getInputStream());
        ObjectOutputStream outToServer = new ObjectOutputStream(clientSocket.getOutputStream());

try{

  do  {
 
       System.out.print("Hello Welcome to the Local Server: \n");
        
       BufferedReader br= new BufferedReader( new InputStreamReader(System.in));
    
  str =(String)br.readLine();
       
        Packet  myPacket = new Packet(i,str);
        
        outToServer.writeObject(myPacket);
        sentence = (String)inFromServer.readObject(); 

        System.out.println("FROM SERVER: Packet SerialNo#" + sentence+" is recieved"); 
      i++;
  
        } while(!str.equals("CLOSE"));      
  } catch(IOException e)
  {} 
        clientSocket.close();    
    } 
} 

//Packet

import java.io.*;

public class Packet implements Serializable{

private int serialNo;
private String data;

  public Packet(int serialNo, String data) {

  this.serialNo = serialNo;
  this.data     = data;
  }
 
  public String getData() {
 
  return data;
  }

  public int getSerialNo() {

  return serialNo;
  }

}
This article has been dead for over six months. Start a new discussion instead.