?
Solved

decode multipart/x-mixed-replace (Server-Push) and display images ??

Posted on 2003-03-08
20
Medium Priority
?
1,440 Views
Last Modified: 2007-12-19
Is it possible to stream a Server-Push-Stream into a java-applet
and dislay the images ?? I am an absulte beginner and dont know how to start ..
can someone help me or send an example code ??
Thanx, Torsten
0
Comment
Question by:Torsten48231
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 6
20 Comments
 
LVL 2

Expert Comment

by:karlika
ID: 8098204
What do you mean by push-stream? You may just connect to a server via a URL-Connection and request the image. The displaying part should not be any problem as far as you have Bitmaps, JPEGs or GIFs. Other formats need a converter.

I would just start building a simple Applet and adding a custom subclass of Canvas for the images.
After that you load the images and display them.

I know this is not exactly a construction manuel, but for starters...

Marko
0
 

Author Comment

by:Torsten48231
ID: 8098319
The Server (Delphi Application) sends a mutipart/x-mixed-replace stream to the client on request ..

the stream look like ->

Content-type: multipart/x-mixed-replace;boundary="stopthis"


--stopthis'
Content-type: image/jpeg


BINARY JPEGPICTUREDATA
--stopthis
Content-type: image/jpeg

BINARY JPEGPICTUREDATA

--stopthis
Content-type: image/jpeg

BINARY JPEGPICTUREDATA
--stopthis--



now i want get the imageparts and display them in the applet .. and when a new image is send (BINARYJPEGDATA) it should be displayed again ... (like a Video)

In Netscape Browser .. i can display the multipart image direct in the browser .. but Internet Explorer can not handle such MIME types .. so i want to do it with an applet

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8102622
You could do it if you were prepared to sign the applet. It could then start a listening socket to which you could connect and send the data.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Torsten48231
ID: 8103269
the applet will be loaded from the server .. i think then the applet dont need to be signed ..
0
 

Author Comment

by:Torsten48231
ID: 8103273
do you have some code-snippets ??
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8103295
I could give you some later. It *does* need to be signed because if it's going to receive a server-side push, then it needs to open a socket at the client end. On the other hand, if it pulls the data instead, then you're quite right, as long as they applet originates from the same server.
0
 

Author Comment

by:Torsten48231
ID: 8103418
ok. it would be very fine if you send some code .. thanks in advance
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8103706
Are you doing push or pull then?
0
 

Author Comment

by:Torsten48231
ID: 8103792
first the applet will load and sends "GET JPG" to server .. the server pushes the jpeg data back to the applet like above  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8103876
Well you can simply get the applet to open a URLConnection to the JPG. It's as simple as that. But what are you going to do with it then?
0
 
LVL 2

Accepted Solution

by:
karlika earned 210 total points
ID: 8103880
It must be pull. And I really think you may just use an URL Connection. Netscape does nothing else.

InputStream is = new URL("address of the server").openConnection().getInputStream();

After that read every image as it comes (until "stopthis") and then use one of these (pick what you think fits best):

http://www.geocities.com/marcoschmidt.geo/java-image-coding.html#pixel

to convert the bytestream to a java-image.
Now you can draw this Image to your Canvas.

I'm willing to give further information as needed ;)

Marko
0
 
LVL 2

Expert Comment

by:karlika
ID: 8103929
uh, im a bit slow today... ;)

Do you have the images only in THIS streamed form or may you rewrite the server so it delivers one image a time - and change this image after 1-2 seconds?

That would make the loading-process much easier, because the applet takes the part of decoding the jpegs to java-images.

Marko
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8103940
If you have your images and applet at the server, you actually only need to call getImage. See http://java.sun.com/j2se/1.4/docs/api/java/applet/Applet.html#getImage(java.net.URL, java.lang.String)
0
 

Author Comment

by:Torsten48231
ID: 8104688
No the images are not on the server .. i get the images from a capturecard or webcam  installed on the "Server-Computer" .. the problem is .. i dont want to read only one image and display it .. i need to get ALL images .. and display them when they arrive at client ... the server send the images as fast as he can ..
the "image-stream" never ends .. only if the server ends the connection or the client disconnects ...

 
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8104759
So it's not on the server as a file as such?
0
 
LVL 2

Expert Comment

by:karlika
ID: 8104825
Do you have a link to this Server of yours? Does it even run yet?

I'd really like to make a few tests with this... ;)

Marko
0
 

Author Comment

by:Torsten48231
ID: 8105067
no sorry .. no version is ready to use .. hmm ..
here is a code snippet .. (Delphi):


        position:=AnsiPos('GET JPG', s);
        if position >  0 then
          begin
            i:=0;
            Athread.Connection.Write('HTTP/1.1 200' + #13#10);
            Athread.Connection.Write('Content-type: multipart/x-mixed-replace;boundary="stopthis"'+ #13#10#13#10);
            Athread.Connection.Write('--stopthis'+#13#10);
            repeat
               Athread.Synchronize(capturenow);
               inc(i);
               try
                  Athread.Connection.Write('Content-type: image/jpeg'+ #13#10#13#10);
                  // here the capture is written to a file but i will use a MemoryStream-Object
                  Athread.Connection.WriteFile(ExtractFilePath(Application.ExeName)+'\cap.jpg',false);
                  Athread.Connection.Write('--stopthis'+#13#10);
                  Athread.Connection.Write('Anzahl der Viewer:'+IntToStr(Connections)+' Nummer: '+IntToStr(i)+#13#10);
               finally
               //
         end;

         until(false);
         end;
         // Ende Serverpushing

now i need only the client to work ..
netscape is displaying the stream as it arrives .. picture for picture .. but Internet Explorer isnt supporting the multipart-x-replace push .. :-|
0
 

Author Comment

by:Torsten48231
ID: 8108225
oki .. i find it out .. but now i have a little bit flickering in the video *snif* . any ideas how to fix it ??

here is the code:

try
          {
               out.println("GET JPG");
                                       
               while(true)
               {
                    int filelaenge;
                    int i;
                    byte bytebuffer[];
                    filelaenge = Integer.parseInt(in.readLine().trim());
                    bytebuffer = new byte[filelaenge];
                    i=in.read(bytebuffer,0,filelaenge);
                    MyImage=Toolkit.getDefaultToolkit().createImage(bytebuffer);
                   
                    if (MyImage != null)
                    {
                         tracker = new MediaTracker(this );
                         tracker.addImage(MyImage , 0) ;
                         
                         try
                              { // wait until image is fully loaded.
                                   tracker.waitForID(0 );
                              }
                         catch ( InterruptedException e )
                              {
                              }
                         repaint();
               
                    }
                    else
                    {
                    //repaint();
                    }
               
               }
               
          } catch (IOException e) {  }



0
 
LVL 2

Expert Comment

by:karlika
ID: 8109797
Everytime you repaint a component, it is first filled with the Backgroundcolor in order to draw on it afterwards. You have to use some doublebuffering. I'm currnetly searching my libraries for some suitable code you may use ...

Marko
0
 
LVL 2

Expert Comment

by:karlika
ID: 8110088
Okay, I'm not fully awake. You do not have to use doublebuffering because you are not drawing anything besides the image. Just add the Method:
public void update(Graphics g) {
  paint(g);
}

to the Component that displays the image.

Marko
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question