Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1526
  • Last Modified:

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

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
Torsten48231
Asked:
Torsten48231
  • 8
  • 6
  • 6
1 Solution
 
karlikaCommented:
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
 
Torsten48231Author Commented:
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
 
CEHJCommented:
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.

 
Torsten48231Author Commented:
the applet will be loaded from the server .. i think then the applet dont need to be signed ..
0
 
Torsten48231Author Commented:
do you have some code-snippets ??
0
 
CEHJCommented:
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
 
Torsten48231Author Commented:
ok. it would be very fine if you send some code .. thanks in advance
0
 
CEHJCommented:
Are you doing push or pull then?
0
 
Torsten48231Author Commented:
first the applet will load and sends "GET JPG" to server .. the server pushes the jpeg data back to the applet like above  
0
 
CEHJCommented:
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
 
karlikaCommented:
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
 
karlikaCommented:
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
 
CEHJCommented:
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
 
Torsten48231Author Commented:
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
 
CEHJCommented:
So it's not on the server as a file as such?
0
 
karlikaCommented:
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
 
Torsten48231Author Commented:
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
 
Torsten48231Author Commented:
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
 
karlikaCommented:
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
 
karlikaCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now