Results 1 to 11 of 11
  1. #1
    tandren544 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Exclamation halp! reading repeatedly from a url...

    i'm working on an engineering app which takes a camera live feed from a given url and updates the live feed in matlab. this is later going to be used for image processing, and with the current setup i am only able to attain a framerate of ~3 fps, where our target is more like 10+ fps.

    my code is actually in matlab, but here's the jist of what i'm doing right now, and then what i want to do.

    NOW:
    create a new URLConnection
    create a new InputStream (URLConnection.getInputStream)
    open a file
    create a new FileOutputStream
    copy the input stream over to the output stream
    close the file
    close the input stream
    close the connection
    rinse, and repeat

    im guessing that connection negotiations are significantly slowing down this whole process, so what i'd like to do is:

    open a URLConnection, InputStream, FileOutputStream (allocate basically)
    while(...) {
    open a temp file
    create associated stream
    push inputstream into fileoutputstream
    display temp file
    refresh inputstream (input image should change each read)
    }
    close everything

    my main problem is, i don't know how to refresh the InputStream without opening a brand new URLConnection.

    sorry for my rambling haha thanks y'all

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    What does "refresh the InputStream" mean?
    Why can't you continue reading for it?

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

  4. #4
    tandren544 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What does "refresh the InputStream" mean?
    Why can't you continue reading for it?
    the inputstream is preloaded with image data when the connection is established. however, this stream needs to be 'updated' as new images are read, so a unique image is retrieved every iteration.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    I assume the stream you are talking about has a source that puts things into it at one end and a target that reads things out of it at the other.

    What does "updated" mean?

    If I write an A and then a B and then a C into the stream. The reader will first read an A then a B then a C from the stream.

    What does "preloaded" mean? In the above example the stream could contain an A and a B before the reader starts to read from the stream.

  6. #6
    tandren544 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    I assume the stream you are talking about has a source that puts things into it at one end and a target that reads things out of it at the other.

    What does "updated" mean?

    If I write an A and then a B and then a C into the stream. The reader will first read an A then a B then a C from the stream.

    What does "preloaded" mean? In the above example the stream could contain an A and a B before the reader starts to read from the stream.
    thanks for the replies, norm. sorry for my stunted explanation haha... what i want is an asynchronous connection.

    on the client side, the image feed will be updated, say 100 times per second. the client side will only be able to access this, say, 10-15 times per second.

    each time the server accesses an image, i want it to grab ONE image from the inputstream and display it in matlab, then 'refresh' the connection, so the inputstream receives one more image, displays it, etc...

    so, the client (feed) is displaying
    A B C D E F G H I J K L M etc...

    and the server sees:
    connect-A-refresh connection-F-refresh connection-L-refresh-etc...

    and, in the case the client displays:
    A

    the server should see:
    connect-A-refresh connection-A-refresh connection-A-refresh-etc...

    URLConnection does not provide an elegant solution to this 'refresh' problem, which is causing me to pull my hair out right now.
    Last edited by tandren544; 07-15-2010 at 11:42 PM.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    connect-A-refresh connection-F-refresh connection-L-refresh-etc...
    Looks like "refresh" here means that the reader is reading and skipping BCDE and going on to F.
    What tells the server to skip over those 4 images?

    then 'refresh' the connection,
    What does "refresh" mean here?

    Which side is outputing the images? The client?

    in the case the client displays:
    A

    the server should see:
    connect-A-refresh connection-A-refresh connection-A-refresh-etc...
    Here the stream would be empty, so the server would know that A was it.

    Another confusing terminology: the client displays
    What does "displays" have to do with writing an image to the stream?

  8. #8
    tandren544 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Looks like "refresh" here means that the reader is reading and skipping BCDE and going on to F.
    What tells the server to skip over those 4 images?


    What does "refresh" mean here?

    Which side is outputing the images? The client?


    Here the stream would be empty, so the server would know that A was it.

    Another confusing terminology: the client displays
    What does "displays" have to do with writing an image to the stream?
    ok, i'll try to cut the extra stuff out and keep it simply to the streams for now.

    the client sends data, namely, jpg images, which are updated as frequently as 100 times per second, to a set url, lets say:

    http://1.1.1.1/image.jpg

    100 times per second, this image changes. now, when i open an input stream from the client (the url which is sending data), initially, there is one image in the input stream, and hundreds more may be added every second.

    i only want to retrieve one image from this stream before closing or flushing it. so, the server will open a connection, set everything up, then pull the single image out of the stream. once the server (the matlab function which will 'display' the images to the screen) is ready to get another image from the client, it will 'refresh' its input stream (flush it somehow), and then take the next available image from the stream.

    as far as i can see, there are two ways to do this.

    the one you're hinting at, which will ideally be much better performance-wise, is to open a single stream and continue to read raw data from it as fast as possible without ever closing the connection. this way, anything that is written to the input stream will instantly be grabbed on the other end.

    however, the problem with this is that the two ends must remain in sync relative to time, since this will be used for image processing. so, i'd rather skip a few images here and there (as you said) in order to preserve the accuracy of the image feed relative to time, if that makes sense to you.

    what i would like to do is refresh the connection each time an image is to be read, without disconnecting and reconnecting completely. in other words, i want to keep the socket open while i reload the file at the url. this will reduce the overhead created by reconnecting every time, while allowing the client and server to stay 'in sync'.

    sorry for the confusion. engineering stunts my language skills.

  9. #9
    tandren544 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Here the stream would be empty, so the server would know that A was it.
    ahh yes i forgot to mention this... this is another problem. i want the server to keep retrieving A over and over again in the case the client becomes stuck.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    i want the server to keep retrieving A over and over again
    That would mean that the sender/client would have to keep sending A over and over again.
    Seems like a waste of resources.
    With an input stream you can use the available() method to know if there is anything more to be read.


    what i would like to do is refresh the connection each time an image is to be read, without disconnecting and reconnecting
    Again what does refresh mean? What is to happen to all the images that are in the stream waiting to be read? Since the stream has buffering and blocked data, there is no way to find where the end of one image/beginning of the next image without reading thru the stream to find it.

    Given my model of the client sending:ABCDEFGHIJKL
    after the server reads A how can it possibly next read F without reading over BCDE?

    Perhaps the client should only send images when the server requests them. Let the client do the skipping.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by tandren544 View Post
    i only want to retrieve one image from this stream before closing or flushing it. so, the server will open a connection, set everything up, then pull the single image out of the stream.
    This is where I'm confused. If the server is making the connection to the client then you have it arse about face. Clients make connections, servers serve connections.

Similar Threads

  1. URL Reading question
    By g123456 in forum New To Java
    Replies: 5
    Last Post: 03-17-2010, 04:07 AM
  2. CMD is not reading commands
    By colonial in forum Forum Lobby
    Replies: 1
    Last Post: 03-15-2010, 03:36 AM
  3. reading from a .txt
    By Flamespewer in forum New To Java
    Replies: 1
    Last Post: 09-14-2009, 09:35 AM
  4. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  5. reading csv file help
    By fritz1474 in forum New To Java
    Replies: 5
    Last Post: 09-04-2008, 09:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •