Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:51:32+00:00 2026-05-27T14:51:32+00:00

Im trying to send an object from client to server and one of the

  • 0

Im trying to send an object from client to server and one of the object states is a vector and the other is a string. I can access the string on the Server side, but the vector contents is zero on the server side..Can someone help me out please..

    // Server
import java.net.*;   
import java.util.Vector;
import java.io.*;
public class SimpleServer {

    public static void main(String args[]) {
        int port = 2002;
        try {
            System.out.println("Hello");
            ServerSocket ss = new ServerSocket(port);
            Socket s = ss.accept();
            System.out.println("Hello 2");
            InputStream is = s.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);
            testobject to = (testobject)ois.readObject();
            System.out.println("Vector size : " + to.vectorX.size() + " and object.id : "
                    + to.id);
/*          if (to != null) {
                for(int i = 0; i < to.vectorX.size(); ++i )
                System.out.println("Output 1 : " + to.vectorX.elementAt(i));
            }   */
            is.close();
            s.close();
            ss.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


// Client
import java.net.*;
import java.io.* ;
import java.util.Vector;

public class SimpleClient {

    protected static Vector<String> vectorX = new Vector<String>();

    public SimpleClient(){
        vectorX.addElement("hello");
        vectorX.add("goodbye");
        vectorX.add("finally");   
    }

    public static void main(String args[]) {
        try {
            new SimpleClient();
            Socket s = new Socket("localhost", 2002);
            OutputStream os = s.getOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(os);
            testobject to = new testobject(1, "theID", vectorX );
            System.out.println(vectorX.size());
            oos.writeObject(to);
//          oos.writeObject(new String("another object from the client"));
            oos.close();
            os.close();
            s.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}


//testobject
import java.net.*;
import java.io. * ;
import java.util.Vector;
class testobject implements Serializable {
    int value;
    String id;
    Vector<String> vectorX; 

    public testobject(int v, String s, Vector<String> vector) {
        this.value = v;
        this.id = s;
        this.vectorX = new Vector<String>();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:51:33+00:00Added an answer on May 27, 2026 at 2:51 pm

    The constructor for your testobject is not using the vector argument. It is rather assigning the vectorX ivar to a new instance, ignoring the parameter provided by the caller:

    public testobject(int v, String s, Vector<String> vector) {
            this.value = v;
            this.id = s;
            this.vectorX = new Vector<String>(); // This is bad
        }
    

    You should instead use:

    public testobject(int v, String s, Vector<String> vector) {
            this.value = v;
            this.id = s;
            this.vectorX = vector;
        }
    

    Note: It’s not common for class names in Java to be all lowercase, or to start with a lowercase letter. As an aside, I think you should rename your class to TestObject.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send an XMLHttpRequest object to my Rails server but the headers
I am trying to send a serialized Java object from a client to a
I am trying to send data from my RESTful client to my RESTful server.
I am trying to send a serialized object from a server process to a
I am trying to send an object over tcpclient from the server to a
I am trying to send an email from a site I am building, but
I am trying to implement a bidirectional client-server program, where clients and servers can
I am trying to make a simple Client-Server application but when I execute the
I'm trying to use AutoBean on the server and client to send and receive
I'm trying to find the best way to transfer data from server -> client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.