• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
angel Pena
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!