• 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

Problem transfering JPG using RMI

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I'm programming a client-server application, where the client ask the server for a jpg file. The server then transfers the file (if found) to the client. I'm having a strange issue where all of the jpg bytes are transfered but when I go to the folder where the client keeps the file, and I try to open the file, my Image Viewer (I'm using GNOME) says "Could not load image 'nameOfFile.jpg'. Error interpreting JPEG image file (Not a JPEG file: starts with 0x00| 0x00".

This also happened to me doing the same application but using sockets instead of RMI, and happens also when using Windows instead of Ubuntu. I'm not sure what I am doing wrong. I'll be thankful if anyone can help me.
 
Greenhorn
Posts: 8
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the io streams you are using. You may not be writing the file properly.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you transferring the JPG through RMI?

Communication in RMI is as follows:
- the client sends method call request with all arguments in serialized form to the server
- the server executes the method with the given deserialized arguments
- the server sends the return value in serialized form to the client
- the client gets the deserialized return value

As you see, any changes to the arguments will not be seen by the client. For instance, the following method will not do what you expect when used in RMI:
The server modifies the StringBuilder, but this is not the client's StringBuilder - it's a copy. This copy is not synchronized with the client's copy.

So if your transfer method passes a byte[] to the RMI server's method like in InputStream.read and you expect it to be modified - well, it won't.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you verifying that:

all of the jpg bytes are transfered

?

Are you sure that you are always treating the contents as byte[]? As Nisha said, check your use of streams - watch out for treating the bytes as characters, for example by creating a String or using a Writer or Reader.

Due to unicode character conversions, an image will not survive being treated as char[] or String.

Bill

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic