By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy. from Socket-stream

P: n/a

I have an application sending JPEGs via a TCP connection.
By now I used a Delphi program on the other side to receive the pics.

Now I want to create a Java applet that does the work of the Delphi
program, but I have problems reading the pics from the socket's
Here's my code:


public BufferedImage getImage()
BufferedImage image;

ImageInputStream stream = ImageIO.createImageInputStream(
_cSocket.getInputStream() ); // _cSocket is of class Socket

image = stream );
catch( Exception e )
System.err.println( e );

return image;


The function returns null. There seems to be no appropriate
Now, when I add the following lines to the function, it works fine:


while( _cSocket.getInputStream().available() > 0 )
byte[] b = new byte[2];

int c = _cSocket.getInputStream().read( b );

if( b[0] == 0xFF && b[1] == 0xD9 ) // FF D) are the last two byte
of a JPEG


But that's not exactly what I wanted. I guess it skips every second
Can anybody explain this phenomenon.

My setup:
Windows 2000
Java 1.4.2_02
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
I've figured out, that; takes too many bytes from the
The first read returns a valid image, but the second time the read
call doesn't find a valid JPEG at the beginning of the stream, because
the previous read took some bytes from the next image. So, when I skip
all bytes until the next FF D9 (End of JPEG) appears, the next read
will succeed too.

Is that a bug in the function? Or am I doing something
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.