InputStream keeps reading forever

Hi,
I have a 'little' problem with input stream. I have a Telnet connection established and I'm reading the input I receive. I read some input and then I send commands. I'm reading the input inside a while loop like this one:
InputStream in = telnet.getInputStream();
char ch = '';
while (condition) {
    ch = (char)in.read();
}The problem is that, when the input is over, in doesn't get out of read and it stays there forever. It doesn't event returns -1, the last char read, anything, it simply doesn't gets out of there. Is there a way to know when there's no more input to avoid this from happening? I can't use read(byte[]) because the input varies and I can't know how many data will be received. There's also no indicator of the end of data like: EOF or -1.
I will appreciate any help.

kazenofairy wrote:
Nope, it's not the condition. And it's not a file what I'm reading, it's the input from a Telnet connection. My condition is:
InputStream in = telnet.getInputStream();
char ch = '';
int chaux = 0;
while (chaux != -1) {
chaux = in.read();
ch = (char)chaux;
}I'm printing the values that chuax and ch are getting, but, when there's no more input, it just stops reading and the loop doesn't continues or breaks.Ah, ok, I missed that part on telnet; the stream obviously didn't hit an end of file condition then so you have to stop reading on another condition such as the end of the line or maybe
the InputStream.available() method can be of any use. Interactive input streams can be messy.
kind regards,
Jos

Similar Messages

  • Why does this loop used to write values to the parallel port keep going forever?

    Have a look at this VI guys. I'm trying to send a sequence of bits (used to trigger an IC). I'm interested in the last bit of the data port (D0). so I'm sending either 0 or 1 to that pin to trigger the IC. it works, but the problem is that the loop keeps going forever and i cant control it. if i send 3 to the loop count, I'm expecting to get: 1 0 1 0 1 0, but it doesnt stop and keeps going forever.
    It seems that the problem is not with the loop. because i deleted the loop and just left the flat sequence so that it executes only once, but still it keeps repeating. How can i make the flat sequence execute only once?
    I'm using a parallel port monitor (parmon.exe) and a LED connected to D0 of the parallel port to check.
    If anybody has an alternative or better method to send the bits to the parallel port, I'd be very thankful.Message Edited by krayzie on 05-14-2005 04:33 PM
    Attachments:
    pport.vi ‏24 KB

    It works just fine here. Place an indicator to the iteration terminal [i] to watch how things progress. Do the number ever increase above N-1 to what you wire to N? I don't think so!
    Also make sure you don't run the VI with the "Continuous run" button. In this case the VI would immediately restart whenever it is finished. use the "Run" button.
    LabVIEW Champion . Do more with less code and in less time .

  • InputStream partial reading problem

    Hi, I have to read a big file partially, in my function as a parameter i will have
    InputStream - 'is'
    byte[] buffer = new byte[1024];
    long sentBytes = 0;
    int bytesRead = is.read(buffer, 0, 1024);
    while (bytesRead > 0) {
    sentBytes += bytesRead;
    bytesRead = is.read(buffer, 0, 1024);
    counter++;
    i'm reading more than i should- how to cope with that? its a problem with last part of stream i suppose..
    bytesRead = is.read(buffer, 0, chunkSize);
    but when i call buffer.length at the end, it prints lower value than 1024, so where is the problem?

    Hi, I have to read a big file partially, in my
    function as a parameter i will have
    InputStream - 'is'
    byte[] buffer = new
    byte[1024];
    long sentBytes = 0;
    int bytesRead = is.read(buffer, 0, 1024);
    while (bytesRead > 0) {
    sentBytes += bytesRead;
    bytesRead = is.read(buffer, 0,
    1024);
    counter++;
    i'm reading more than i should- how to cope with
    that? its a problem with last part of stream i
    suppose..
    bytesRead =
    is.read(buffer, 0, chunkSize);
    but when i call buffer.length at the end, it prints
    lower value than 1024, so where is the problem?How much are you actually trying to read? It looks like your code will keep reading until the end of the file is reached.

  • I keep trying to download 3.6.17 and it just keeps 'downloading' forever. Never finishes. Mac OS 10.5.8

    I keep trying to download 3.6.17 and it just keeps 'downloading' forever. Never finishes. Mac OS 10.5.8
    The download box with the 'barber-pole' moving just goes on and on.

    If you have problem with updating Firefox then easiest is to trash the currently installed version to do a clean install of the new version.
    Download a new copy of the Firefox program and save the DMG file to the desktop
    * Firefox 3.6.x: http://www.mozilla.com/en-US/firefox/all-older.html
    * Trash the current Firefox application to do a clean (re-)install
    * Install the new version that you have downloaded
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.
    Firefox 4 doesn't run on a PowerPC Mac.<br />
    Firefox 4 requires at least OS X 10.5 and an Intel Mac.
    * http://www.mozilla.com/firefox/4.0/system-requirements/
    For a Firefox 4 compatible version that runs on Mac OS X 10.4.11 or Mac OS X 10.5.8 (PowerPC) you can look at:
    * http://www.floodgap.com/software/tenfourfox/

  • The latest version of itunes (10.2.2) freezes immdiately after connecting a device when trying to sync to ipod, iphone or ipad. The beachball just keeps spinning forever or until I force quit

    The latest version of itunes (10.2.2) freezes immdiately after connecting a device when trying to sync to ipod, iphone or ipad. The beachball just keeps spinning forever or until I force quit

    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Application Support/SyncServices
    Right-click or control-click the line and select
    Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item selected. Quit the application if it's running. Move the selected item to the Trash. Relaunch the application and test.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • My IPhone 5 is set on keep,text forever but I can only go back to mid August how do I access the rest of my text?"

    why can I not access all my text when my setting is 'keep text forever' I can only get text upto August?

    Hey staceypryz,
    Thanks for the question. I understand that your iPhone is unexpectedly restarting and displaying only the Apple logo. For this issue, it may be best if you contact Apple Support, as recommended in this resource:
    iOS: Device unexpectedly restarts, displays Apple logo, or powers off
    http://support.apple.com/kb/TS5356
    Resolution
    Make sure your iOS device is up to date. If you still see this issue after updating, contact Apple Support.
    Learn what to do if your iOS device won't start up past Apple logo or doesn't respond.
    Thanks,
    Matt M.

  • InputStream and Reader

    For the program that I'm writing, I'm redirecting the default streams, so I made extended InputStream, overrode ALL the functions, and used System.setIn.
    However, a common class that I use for IO in my previous console programs use Readers. I figured out that I needed to return a
    (char) -1
    after my buffer has ended as the end-of-stream.
    However, if I only return it for a set number of times, like 1 or 50000 times, the Reader won't accept that end-of-stream, and keeps reading! If I don't stop returning the end-of-stream, the stream can't be read for a second time (the Reader keeps returning end-of-streams)! How should I solve this?

    You guys aren't understanding the purpose of the
    class. I want to redirect System.in.to a applet or a
    swing app. So, I want the Reader to accept the
    input, but not close the stream permenently. I hope
    that clear things up for a bit.Well, I had the same problem with my application, it would write the data fine, but not close the FileOutputStream, which caused my application to crash (because I put in safeguards) What I did was create variables for each thing being written, wrote a class, like:
    public void Create() //coded 4/12/2006
              create = new FileDialog(dialog,"New Game v1.0", FileDialog.SAVE);
              create.show();
              file_name = create.getFile();
              f = new File(file_name);
              if (file_name != null)
              { try
                        FileOutputStream fos = new FileOutputStream(file_name);
                        DataOutputStream dos = new DataOutputStream(fos);
                        level = "1";
                        cur_HP = "10";
                        max_HP = "10";
                        atk_str = "10";
                        def_str = "10";
                        cur_exp = "0";
                        exp_ned = "100";
                        loc_x = "0";
                        loc_y = "0";
                        dos.writeUTF(level);
                        dos.writeUTF(cur_HP);
                        dos.writeUTF(max_HP);
                        dos.writeUTF(atk_str);
                        dos.writeUTF(def_str);
                        dos.writeUTF(cur_exp);
                        dos.writeUTF(exp_ned);
                        dos.writeUTF(loc_x);
                        dos.writeUTF(loc_y);
                        System.out.println("File Created Sucessfully: " + file_name);
                        fos.close();
                   catch (IOException e)
                        System.out.println("There was an Error Creating the File: " + file_name);
                        System.out.println(e);
         }which opened the FileOutputStream and DataOutputStream, wrote the variables to the file (which were ints converted to a String), and closed the file. What I would try to do is to write your variables to the file, then put a end variable (like an int set to the value of 1728274672 or some other number of your choice), and when your reading your file, have an if/else statement like:
    if(temp_process[i] != 1728274672)
    process[i] = temp_process;
    i = i + 1;
    else
    bufferedvariable.close();
    i hope this makes sense
    Message was edited by:
    g@m3r

  • My iPod 5 can't connect to wifi. It connects to personal hotspots but no to my home wifi. I tried resetting the network settings but no change. I put the right password but it just keeps loading forever. What should I do??

    My iPod 5 can't connect to wifi. It connects to personal hotspots but no to my home wifi. I tried resetting the network settings but no change. I put the right password but it just keeps loading forever. What should I do??

    Does the iOS device connect to other networks? If yes that tend to indicate a problem with your network.
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on your router
    .- Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network      
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem and it does not connect to any networks make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • I am new to mac, but i keep reading about Mountain lion.  I just bought my Mac book Pro less then a month ago.  my current software is OS X 10.8.2, Do i already have mountain lion?  How do I check to see?

    I am new to mac, but i keep reading about Mountain lion.  I just bought my Mac book Pro less then a month ago.  my current software is OS X 10.8.2, Do i already have mountain lion?  How do I check to see?

    As the others have stated, you're on Mountain Lion with 10.8, anything. But you can check your version of the software by going to the apple in the upper left corner of the screen and clicking it and selecting "About This Mac". That will open a box that shows your software version. Once there you can click on "More Info" that will tell you everything about your specific mac configuration.
    Welcome to the Mac family.

  • I'm having difficulty downloading apps to Iphone using my PC. I keep reading that there is a "device" button to click on in Itunes Store but it's not visible on my PC. Any tips?

    I'm having difficulty downloading apps to Iphone using my PC. I keep reading that there is a "device" button located in the Itunes page... but I don't see it.

    What do you mean?
    You buy an app from itunes on your computer?
    If so, then sync it to your iphone.
    Open itunes, connect iphone, select the apps you want under the apps tab and sync.
    iPhone User Guide (For iOS 4.2 and 4.3 Software)

  • Bought 2nd ipod nan0, computer keeps reading error message? is there a quick fix for this?

    Bought a 2nd ipod nano , computer keeps reading error message? is there a quick fix for this?

    There are a lot of different error messages, which one are you getting. Verbatim with the number please.

  • My ipod touch 5 wont connect to wi-fi it just keeps loading forever

    My ipod touch 5 wont connect to wi-fi it just keeps loading forever.
    My sisters ipod5 connects just fine and they're right beside each other. i already tried resetting the network settings, nothing has worked.
    any advice?

    Does the iPod connect to other networks?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • I keep reading that i need converter software to import Canon DSLR (Mark II or D6) H.264 MOV file to iMovie? True? I'm confused.

    I keep reading that i need converter software to import Canon DSLR (Mark II or D6) H.264 MOV file to iMovie? True? I'm confused.

    iMovie 9.0.9 is the latest version you can run unless you upgrade to the Mavericks operating system (OS 10.9).
    Your profile (at the bottom of your post) mentions OS 10.4.11 (Tiger) which is why I mentioned that.
    The list of supported cameras is not comprehensive  but articles such as:
    https://getsatisfaction.com/apple/topics/make_canon_eos_6d_h_264_1080p_footage_e ditable_in_fcp_imovie
    do indicate that conversion is needed before import, at least for iMovie 9.  Although it's a recent article it doesn't specifically mention  iMovie 10.
    iMovie 10 has a very much changed interface and a different folder structure so upgrading is not trivial so I would not advise rushing into upgrading.
    Maybe someone with knowledge of this camera can help.
    Geoff.

  • I installed Trusteers rapport and now can't  open internet pages I have been visiting for ages. I tried uninstalling bu i keep reading Apple event timed out! Help!

    How do I install Trusteers rapport?
    I keep reading
    apple event timed out!
    Pleas help?!

    Rapport has never previously worked on a Mac. How to uninstall Rapport, by Trusteer:
    http://www.trusteer.com/uninstalling-rapport-mac-os
    However, Trusteer recently posted this in another thread:
    We would like to recommend you to download Rapport's updated version, as we suspect the problems you were experiencing have already been resolved.
    You can download the latest version here:
    http://download.trusteer.com/Gcur4Wtnu/leopard/Rapport.dmg
    Please restart your browser after the installation completes and let us know if the problem persists.
    If the problem persists, we would be very interested in fixing it.
    Please note that we offer 24/7 free technical assistance.
    Should you need additional assistance, feel free to contact us by submitting the following form: http://www.trusteer.com/support/submit-ticket
    We also have helpful information available in our FAQ: http://www.trusteer.com/support/faq

  • Recently installed updated IOS on iphone and ipad, but since then I no neither appears in iTunes; keep reading other support responses about the "devices" button, but I do not see it; running 11.1.5.5

    Recently installed updated IOS on iphone and ipad, but since then I no neither appears in iTunes; keep reading other support responses about the "devices" button, but I do not see it; running 11.1.5.5

    Hi Gray Don,
    Welcome to the Support Communities!
    The article below may be able to help you with this.  Follow the steps in order, but step 5 resolves the issue in most situations.
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    Cheers,
    - Judy

Maybe you are looking for