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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:27:24+00:00 2026-06-11T18:27:24+00:00

I have this problem, and I can’t figure it out whats is wrong. I

  • 0

I have this problem, and I can’t figure it out whats is wrong. I have searched on all over the internet, but without success.

So, I have to send an object over sockets in Java, and I can’t figure out how to do it. I tried so many ways. I serialized the object, I tried to write the object directly. But nothing seems to work.

The detail is that I have a chat running in parallel. And sometimes when i open an ObjectOutputStream, or ObjectInputStream, I get busted in a deadlock. And I guess you guys could help me.

Its a hangman game where the clients connects to the server, and the server should send a random word, which is a object, to clients.

Server:

        try{
            socketConexao = socketRecepcao.accept();

    toClient = new DataOutputStream(socketConexao.getOutputStream());
    fromClient = new BufferedReader(new InputStreamReader(socketConexao.getInputStream()));

            //starts the chat
    Thread chat = new Thread(this);
    chat.start();

    }catch(IOException e){}

           //i dont really know how to send the object

    try{
        byte[] bytes = serialize(palavraSorteada);
        toClient.write(bytes);
    } catch (IOException e){
        e.printStackTrace();
    }

Client:

    socketCliente = new Socket(ip, port);

    toServer = new DataOutputStream(socketCliente.getOutputStream());
    fromServer = new BufferedReader(new InputStreamReader(socketCliente.getInputStream()));

            // starts the chat
    Thread chat = new Thread(this);
    chat.start();

    }catch(IOException e){System.exit (0);}

            // and dont really know how to receive the object

    try{
        ObjectInputStream os = new ObjectInputStream(socket.getInputStream());
        palavraSorteada = (Palavra) os.readObject();
        os.close();
    }catch(Exception e){
        e.printStackTrace();
    }
  • 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-11T18:27:25+00:00Added an answer on June 11, 2026 at 6:27 pm

    It should be fairly obvious what wrong here (from your description): You use one communication channel to send two different kinds of data. Since the receiving end can not predict what its going to receive you need to add information what comming next, so the receiving end knows what to do.

    And probably noone is going to the trouble to figure out what your code fragments are really doing, reduce the fluff to what you want to ask about or even better make a one class copy&pasteable runnable example (as short as possible) that demonstrates the issue.

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

Sidebar

Related Questions

I have this code and can't figure out what seems to be the problem:
I have this problem I can't figure out, I query the DB this way:
I have had this problem crop up a few times and I can't figure
I have this problem and I can't seem to find on the Internet for
I have this problem, I can create a setup for my app/database but everyone
Looks like others have had this problem but I can't seem to find a
I try to google, but I can't fixed my problem. Many people have this
I have this problem that I can ref a button for control it. I
I have worked on this problem for my entire day and can't solve it.
I have a problem that I can't resolve. Let's say I have this map

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.