Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: repeatedly reading from a url? anyone?

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default repeatedly reading from a url? anyone?

    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
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: repeatedly reading from a url? anyone?

    See posts on the other forum.

    Could you provide links to all the forums where you have posted this question?

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: repeatedly reading from a url? anyone?

    I'd suggest trying to do this using a Socket rather than establishing the connection every time. Seems like you want to establish a Client/Server pair...see
    All About Sockets

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: repeatedly reading from a url? anyone?

    Quote Originally Posted by copeg View Post
    I'd suggest trying to do this using a Socket rather than establishing the connection every time. Seems like you want to establish a Client/Server pair...see
    All About Sockets
    this is interesting, but i can't open a tcp socket because i'm actually reading the raw image data from the url... for example, i would read an image into matlab from a url such as:

    http://1.1.1.1/hello/world.jpg

    i don't have access to the remote url which i am reading from, so i can't create a client-side application to send the necessary data.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: repeatedly reading from a url? anyone?

    So the images being written by the server every update? Is it over-writing the same image every time, or writing to multiple images? You may want to consider spawning a few threads to work in parallel rather than tying up a single thread trying to do all the work. This may have its own problems such as coordinating the threads and multiple downloads of the same jpg, but it might point you in the right direction.

Similar Threads

  1. Help with reading from file
    By drazenmd in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 15th, 2010, 03:43 AM
  2. Reading file
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 3rd, 2010, 03:14 AM
  3. Anyone Help me in XML file Reading??????????
    By goplrao in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 2nd, 2010, 11:04 AM
  4. Reading from RSS server
    By Tisofa in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: August 18th, 2009, 04:04 AM
  5. [SOLVED] Problem in reading a file from java class
    By aznprdgy in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: March 23rd, 2009, 09:31 AM