Results 1 to 2 of 2
  1. #1
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

    Default Sending a Vector to TCP server

    Hi,

    I want to send a Vector containing many objects from TCP client to the TCP server.

    Java Code:
    Vector [Students] vector = new Vector [Students] ();
    Please advice me how can I do that.

    - PEACE

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Java Code:
    package one;
    
    import java.io.FileOutputStream;
    import java.io.ObjectOutputStream;
    import java.io.Serializable;
    import java.util.Vector;
    
    public class VectorTest {
    	public static void main(String[] args) throws Exception {
    		Vector<Student> vector = new Vector<Student>();
    
    		vector.add(new Student());
    		vector.add(new Student());
    		vector.add(new Student());
    		vector.add(new Student());
    
    		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
    				"test"));
    		out.writeObject(vector);
    	}
    }
    
    class Student implements Serializable {
    
    	private static final long serialVersionUID = -135535857245815748L;
    	private String name;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    }
    Make sure that Student is Serializable and instead of FileOutputStream make it outputstream of socket. In the server side make sure it recieves the inputstream as ObjectInputStream..

    Hope it helps ..
    dont worry newbie, we got you covered.

Similar Threads

  1. Sending text to printer
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 05-25-2009, 06:14 AM
  2. Sending out UDP pockets
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:07 PM
  3. Sending Mail Using Sockets
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:05 PM
  4. sending jar files from client to server?
    By gobinathm in forum New To Java
    Replies: 2
    Last Post: 11-13-2007, 05:12 AM
  5. Problem when sending application server with RAD 6
    By Marcus in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 06:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •