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 8158087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:30:10+00:00 2026-06-06T17:30:10+00:00

I am trying to send objects across a socket for a game, but they

  • 0

I am trying to send objects across a socket for a game, but they take a long time to send and can cause the game to hang. I want to use BufferedOutputStreams and BufferedInputStreams to send the data, but my ObjectInputStream won’t initialize on the server side when I use the BufferedOutputStream on the client side. The weird thing is that no errors are thrown.

I’m only providing the code involved because it would take a long time to explain what’s going on otherwise. Two clients are initialized each game.

/*Server Code*/

ObjectOutputStream toClients;//stream to both players
ObjectInputStream fromClients;//stream from both players
Socket client1;//player one socket
Socket client2;//player two socket
public RunGame(Socket client1, Socket client2)throws IOException//constructor of a new thread
{
    this.client1=client1;
    this.client2=client2;
}
public void run()//for the thread
{
    try{
        this.createGame();
        /*
         rest of code for server when running game
         */
    }
    catch(IOException e){e.printStackTrace();}
    catch(ClassNotFoundException e){e.printStackTrace();}
}
public void createGame()
{
    try{
        System.out.println("about to create");//this prints out
        fromClients=new ObjectInputStream(client1.getInputStream());//first initialization

        System.out.println("created");//this doesn't
        String s1=(String)fromClients.readObject();

        fromClients=new ObjectInputStream(client2.getInputStream());//sets input to player 2
        String s2=(String)fromClients.readObject();
    }
    catch(IOException e){e.printStackTrace();}
    catch(ClassNotFoundException e){e.printStackTrace();}
}

/*Client Code*/
Socket sock;//created in the constructor of the thread
ObjectOutputStream toServer;
ObjectInputStream fromServer;
public void run()
{
    try{
    System.out.println("about to create");//this prints
    toServer=new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream(),8*1024));//bufferedoutputstream is here
    toServer.writeObject("String that is to be sent to server");
    System.out.println("written");//this also prints
    }
    catch(IOException e){e.printStackTrace();}
    catch(ClassNotFoundException e){e.printStackTrace();}
    /*
     rest of client code
     */
}

I’ve been through all of the forums but can’t find anything that works, which makes me assume that I’m doing something very novice. Thanks for any help you can give!

  • 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-06-06T17:30:13+00:00Added an answer on June 6, 2026 at 5:30 pm

    You’ll need to .flush() your ObjectOutputStream otherwise the BufferedOutputStream won’t send its output to the socket.

    • 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 a post request to Parse: https://parse.com/docs/rest#objects-creating . Can't get it
I'm trying to serialize objects to send over network through a socket using only
I am trying to send a message with multiple objects but just cannot get
I am trying to send an object across GWT RPC (GWT 2.4). The object
I am trying to send objects over sockets in android emulators. Each emulator sends
I'm using asp.net mvc2 and trying to send a list of json objects with
i am trying to send an Object via socket. its object Net public class
i'm trying to send a QList as a parameter to another class but for
In my project I've added a newsletter feed. But when trying to send emails
I've had problems trying to send JSON to ASP.NET MVC Controllers. I don't want

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.