title: Sending vectors over TCP-is it done using the ObjectOutput?
body: <p>Okay,I am working on a program to hold the names and paths of multiple files within vectors and sending these from the server to the client. So I have simply tried to send a single vector with the single entry for one file,but to no avail. The vector initialization in the Client code does seem a bit weird, is it incorrect to use the ObjectInput and ObjectOutput interfaces to send vectors? Or am I just doing it incorrectly?
  Server code:</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  import java.util.*;
      class TCPServer
      {
     public static void main(String argv[]) throws Exception
        {
           String clientSentence;
           ServerSocket welcomeSocket = new ServerSocket(6789);
           Vector&lt;String&gt; name = new Vector&lt;String&gt;(3, 1);
           File f0=new File("C:/Downloads","hjd");
           name.addElement(f0.getName()); 
  
  
           while(true)
           {
              Socket connectionSocket = welcomeSocket.accept();
              BufferedReader inFromClient =
                 new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
              DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
              clientSentence = inFromClient.readLine();
              if(clientSentence!="hjd")
              outToClient.writeBytes("Please enter correct directory/filename");
              else{
              OutputStream socketStream = connectionSocket.getOutputStream();//output stream where the object is to be written
              ObjectOutput objectOutput = new ObjectOutputStream(socketStream);
              objectOutput.writeObject(name);//no error during compilation of this line however
  
  
  
      } 
    }
  }
  </code></pre>
  
  <p>And the client code which gives me an incompatible types found error in the vector declaration line:</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  import java.util.*;
  
  
  class TCPClient
  {
   public static void main(String argv[]) throws Exception
   {
    String sentence;
    System.out.println("Enter name of file as hjd");//I will later expand this to add more options
    BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
    Socket clientSocket = new Socket("localhost", 6789);
    DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
    sentence = inFromUser.readLine();
    outToServer.writeBytes(sentence + '\n');
    InputStream socketStream = clientSocket.getInputStream();
    ObjectInputStream objectInput = new ObjectInputStream(socketStream);
    Vector&lt;String&gt; name = objectInput.readObject();//This is the line I am recieving an error on,saying "incompatible types found"
    System.out.println("The name of file is:"+name.get(0));
    clientSocket.close();
   }
  } 
  </code></pre>
  
  <p>Summarizing, can I send a vector using these interfaces? If no, then how do I send a vector over TCP? If yes, what is the proper declaration of the erroneous line,since this one does not even have size or incr of the vector mentioned? </p>
  
  <p>EDIT--
  Now thanks to ALex, the error is gone. I have edited that declaration as so:</p>
  
  <pre><code>if(objectInput.readObject() instanceof String){ 
     String a=(String)objectInput.readObject(); 
     System.out.println("The name of file is:"+a); 
  }else if(objectInput.readObject() instanceof Vector){
     Vector&lt;String&gt; name=(Vector&lt;String&gt;)objectInput.readObject(); 
     System.out.println("The name of file is:"+name.get(0)); } 
  </code></pre>
  
  <p>But while running of the program an exception is generated saying my ObjectInputStream is corrupt. What am I missing?</p>