• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error while sending and image through socket: java.io.StreamCorruptedException: invalid type code:3B

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys i'm new to these forum, I came here looking for answers to a problem i'm having. i'm making a bomberman game and it need to work in LAN. i need to send an image, 2 ints and an object from a client (the game) to a server, and back to another client (another game). Right now im just trying to send all those things forma a game, to the server and back to the game.The problem im having occurs when i try to send an image a second time. This is my code for the server part:


This is the Client part of the Game code:

All works ok except for the image part. The client sends the image, the server receive it, and re-sends it and the client receive it. but then it throws this error:

the specific place where the error occurs is in line 90:


Any idea of why this error is happening? Any help is appreciated
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it's the server which throws the exception, not the client. Look at the stack trace and you'll see code from the Server class there.

The error message says that the server expected to receive a Mensaje object, but instead there was something else in the stream it's reading from. Or maybe there was nothing -- anyway I don't know what 3B means there. So all that sending back and forth isn't working the way you thought it was working.

One thing I notice is that you're connecting two different output streams to the socket's single output stream, and same for the input streams. That sort of thing often leads to problems with buffering, so I would try to do everything with a single output stream instead, to avoid that problem. It looks like you tried to avoid the problem by calling flush(), but you aren't calling it often enough.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic