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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:04:21+00:00 2026-05-11T03:04:21+00:00

Leading on from my previous questions I am going to try and clarify one

  • 0

Leading on from my previous questions I am going to try and clarify one of the problems I am facing.

I am trying to create a multiplayer version of PacMan.

A simple overview of how i’ve made my application is that I have a server which has a ServerSocket which is constantly listening on a specific port. Once a client connects it creates a thread in which all the transferring of data takes place. It first listens for the Direction in which the client wants to move and then sends the updates back to the client. On the client side it’s the reverse of this sending the direction and then waiting for the update to be received. This is done using ObjectOutput/Input Streams. There is also a game class which has all the game logic and this has the game loop which each looping calls each of the connected players serverThread.exchangeDatas() method.

My game works ok with one client connected but as soon as another client joins (locally is all that i’ve tested, but this should work right?) It crashed my game in the Server thread producing the following error java.io.StreamCorruptedException: invalid type code: 00.

Is the code that trips this exception

        Object o = in.readObject();         if (o instanceof Direction)         {             // Get new location             player.setDirection((Direction) o);         //System.out.println('Got: ' + (Direction)o + ' new location: ' + player.getNextLocation());         }          // Send gameState          //System.out.println('Sending data');         Data data = new Data(game.getGameState(), game.getScared(), game.getScareLeft(), player.getLives(), player.getScore());         out.flush();         out.writeObject(data);         out.flush();         out.reset(); 

Server code

ServerThread code (the one that crashes in the exchangeData method

Client Controller code

Game loop code – line 42 is what calls the exchange data method

Any help would be amazing with these.

http://www.mediafire.com/download.php?nwwqmzywfom

here’s a download to both the client and the server (they are netbeans projects)

Sorry for my messy code =[

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T03:04:21+00:00Added an answer on May 11, 2026 at 3:04 am

    Multithreading needs synchronisation. Are you using a synced stream (or syncing the access to the stream yourself)?

    Update: The code sample given may very well be called from multiple threads. If multiple threads access the same stream, errors like the ones you are experiencing may very well occur.

    I suggest having a look at http://java.sun.com/docs/books/tutorial/essential/concurrency/sync.html.

    By marking a method/class synchronized, the runtime will make sure that this method/class will be active in no more than 1 thread at the same time. This is actually a vast and difficult topic, so take some time to learn the basics and make sure you understand the basic problem. 🙂

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

Sidebar

Related Questions

Leading on from a previous question FCM Clustering numeric data and csv/excel file Im
Continuing from my previous post https://stackoverflow.com/questions/14051282/eap-jboss-log-txt-file-getting-large-space , I'm using My Eclipse as ide for
In my previous question Moose - Loading values from conf files... Jack Maney was
I am continuing on from a previous question relating to loading instances of plugins
Currently I am loading data from a previous session into my application using the
I need to strip leading spaces from a column in Oracle. I've Googled but
How can I separate the leading letter from the trailing number in each of
How do I strip leading and trailing spaces from a string? For example, "
i need to get items from a List with no leading or trailing white
I looked around internet and was always looking like from previous 6 months for

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.