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

  • SEARCH
  • Home
  • 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 6731277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:30:33+00:00 2026-05-26T10:30:33+00:00

I have an array of int which I want to send to other server

  • 0

I have an array of int which I want to send to other server using socket programming but it does not work correct I am wondering to know that should I serilized my array or not?

 public Integer[] array=new Integer[5]; 
 //I give some dummy value to array then I send. I have no error and the other side
 // receive it but with wrong value      
 in=new ObjectInputStream(client.getInputStream());
 out=new ObjectOutputStream(client.getOutputStream());
 out.writeObject(new packet(array));  

  import java.io.Serializable;
  public class packet implements Serializable
   {
     public Integer[] vec=null;
     public packet(Integer[] vector){
     vec=vector;}
   }
  //On the other side I have in=new ObjectInputStream(client.getInputStream());
    private packet getPacket() throws IOException
    {
        packet p;
    try {
            p=(packet) in.readObject();
            if (p != null)              
                return p;
        } 
    }

   `
  • 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-26T10:30:34+00:00Added an answer on May 26, 2026 at 10:30 am

    Everything here is OK. The devil is in the details, though. It’s clear that this isn’t the real code, but rather your summary of the code, and so you’ve accidentally fixed something while summarizing it. The most likely problem you’re having is that Java serialization will, by default, only write a given object to a stream once; so if you write an array, change the contents, and write it again, the second instance will come over the wire as just a reference to the first, with the first set of values. Cloning the array in your “packet” constructor, as someone else has mentioned, would definitely help!

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

Sidebar

Related Questions

I have an int array which has no elements and I'm trying to check
I have an int array for which i have allocated space for 100 elements.
I have an array which looks like this: $arr = ( [0]=>Int(2) [1]=>Array( ....)
I have an array of ints and a list of objects which contain int
1) I'm trying to create CSV file using NSMutableArray(array of array) which I want
I have an array of objects which I want to sort based on one
I have two big numbers (type int) which are stored in array with a
Possible Duplicate: Remove duplicates from array I have an int array which contains a
I have a std::array of CPoint objects which I want to output in an
I have a char array which contains some value . I want to copy

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.