Sockets: How do I know how much I can read from a socket?

Hi everyone,
I've opened a socket connection to a cisco router and want to read some of its databases. These are the main part of my code:
Socket so = new Socket(routerIP, routerPort);
BufferedReader br = new BufferedReader(
new InputStreamReader(so.getInputStream()));
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(so.getOutputStream()));
// user/password entered.
bw.write("show ip alias\r\n");
bw.flush();
while ((in = br.readLine()) != null) {
System.out.println(in);
so.close();
The problem occurs in the "while" loop at the end of the code. The last line that the router is sending doesn't have a \r\n at the end and therefore my readLine command waits indefinitly.
Well, I guess I can change that command with a simple read but still it won't be general. I'm looking for a command like "available" in socketImpl that tells me the number of bytes that I can read from the server beforehand.
Any solutions?????????????
Thanks,
Ali.

Ok, that much I know from the router. It supports
telnet. So, basically if a telnet client can tell when
it has read all the data coming from the router and
when it has to wait for user to input the data, I have
to be able to do so too.Hi, telnet does not know that it has read all the data coming from the router or from you; It waits for data from both sources (the router and you), and then retransmits that data to (you or the router respectively.)
telnet must be sending and receiving data byte by byte
cause what we type is displayed on the screen if the
server echos the characters back to the client.
Any suggestions, anyone knows of a simple telnet
source?True. In particular, telnet does not care whether there is any carriage return or linefeed characters. It just retransmits whatever it gets from the source to the destination, except that it looks for particular escape sequences from the data source, such as the sequence for shutting out echo when you enter passwords.
In your case, I am not sure what you want to achieve. I think you are trying to find the end-of-data but the end-of-data is not unambiguously terminated by an end-of-line. Maybe you need to find some other character or even strings for that purpose. You may even need to process the whole data received in order to determine the end of it.
However, if you just want just that answer from the router and no more, you can send your logout after your query, so that after the router replies your queries, it also closes the connection and your BufferedReader.readLine() will return.

Similar Messages

  • I have a second generation I Pod touch.  How do I know which games I can download from the Apple Store?

    I have a second generation I Pod touch.  How do I know which games I can download from the Apple Store?

    Hello, Suzanne. 
    Thank you for visiting Apple Support Communities. 
    Unfortunately there isn't a list available at this time for applications that are specific for your iOS/Software version.  However, once you know which iOS/Software version you have installed, you can browser various applications and look for ones that meet your system requirements.  I have included a screenshot below on how to look for this information. 
    iPhone, iPad, iPod: How to find the software version
    http://support.apple.com/kb/ht2188
    Cheers,
    Jason H. 

  • HT4623 I lost my apps and iTunes after a restore, but it says there isn't enough space on the iPhone 4. How do I know how much space needs to be freed up? I keep deleting photos and videos, but I'm still getting the same message.

    I did an iphone 4 software update. It then asked me to do a "restore" in order for me to be able to use the latest iTunes. I did a "restore" to "factory settings" (this was the only option listed) thinking I'd be able to sync later and get everything back and ended up losing all my purchased apps and iTunes. When I open iTunes, "Welcome to your new iphone" and it says I can re-do the "restore" and choose my lastest update. I assume this will give me back my apps and iTunes. When i choose to do this, it says there isn't enough space on the iPhone. How do I know how much space needs to be freed up? I keep deleting photos and videos from the phone, but I'm still getting the same message every time I re-try. I don't want to delete everything, but I don't know what to do...? Thanks!

    Thanks but I think it has something to do with the 'restore'. in the newest iTunes 11, when I click on the tab "iphone", it redirects me to the "welcome to your new iphone" page and asks about doing a 'restore'. I already did a 'restore', but it went to the original factory settings and I want to 'restore' to my lastest back up as of April 12. When I choose that option, it says my iphone doesn't have enough space. I don't know how much I need to delete in order to make it work. I've deleted lots, but it only has 4.1 GB available. I'm not sure why this isn't enough to do a 'restore'. I don't want to delete all my photos and videos, but maybe I will have to?...7.7GB is used up for that. I can't sync or do ANYTHING...

  • How do I know how much storage I have left available on my iCloud?

    How do I know how much storage I have left available on my iCloud? I know there has to be a way to know this.

    Welcome to the Apple Community.
    settings > iCloud > storage & back up > manage.....

  • How do I know how much is on my itunes gift card?

    How do i know how much is left on my itunes gift card?

    Look at the top right corner of the itunes page by your user id.

  • HT5035 How do you know how much your code still has

    I got a card that has a cod how do you know how much is still in the card

    I meant code

  • HT1766 Restore backup function says there is not enough space on my iPhone to restore backup. How do I fix this/how do I know how much space I need on my iPhone?

    My family member's iPhone recently erased all of its contact information, with no action taken by my family member. She is trying to use the restore backup function to recover her contacts.
    The restore backup functions says that there is not enough space on my iPhone to restore backup. How do I fix this/how do I know how much space I need to complete this backup?
    We have removed the majority of pictures from her phone, and she has 4.1 GB of memory free.
    Thank you!

    You need at least as much space as you have used on the iPod. Could be as much as 64 GB but is probably much less.
    Find a way to delete what you do not need on the computer. Start by emptying the Recycle Bin.
    This may be applicable: iOS: 'Not enough free space' alert when trying to sync

  • How do you know how much harddrive space you have left

    How do you know how much hard drive space you have used

    Apple Menu>About This Mac>More Info>Storage

  • HT4847 how do I know how much storage I am currently using?

    How do I know how much storage I am currently using?

    Go to Settings>iCloud>Storage & Backups>Manage Storage
    From there you can find how much and which files are in a backup, and how much different apps use to store data files.  At the bottom of the screen is the size of the mail storage.

  • How do I know how much storage I'm using?

    How do I know how much storage I'm using?

    Ah, we don't track the size of all the originals files since most often users will only view the files rather than actually download them.  This doesn't require the entire file to be downloaded, just a smaller version of it.  Do you actually download the files, or view them? 
    For a different way to clean up space, try the following:
    On your iphone or ipad, go to the library view for each library and look at the bottom left cloud icon above the libary icon. Next to that you will see "up to date" if it has completed the sync.  You can click on the cloud icon for more information. Anytime your library is up to date, you can clear the cache if you wish to regain some space. This is done in your Library settings in Revel. Tap the 3 parallel lines (version 2.1) in the top left corner. Then, tap the i in the circle to the right of the library you want to clean up. Next, tap the 'Clear Cache' button and give Revel a few minutes to process files.

  • How do I know how much I have selected in GB

    When I try to sync I get an error telling me there's not enough room on the iPod. How do I know how many GB I have selected in iTunes before I hit sync? Is just a guessing game, or is there a way to find this out?
    Thanks.

    If your library is larger than the capacity of the iPod the use the update option 'Sync Music - Selected playlists'. When you open the playlist it will tell you at the bottom of the main window how much is in the playlist in terms of song, hours and GBs.
    Open iTunes and create a playlist to update your iPod from, call it -My iPod for example (the dash will position it at the top of the playlists in Sources). Drag whatever content you want to have into the playlist. Now connect your iPod and when it appears in the Source list click on the iPod icon to bring up the preference tabs in the main pane. Go to the Music tab and choose Sync Music and the Selected playlists radio button. Choose the playlist you just made from the selection and click Apply. You can also sync from any existing playlists by choosing the same setting, you just need to make sure that the size of the playlists don't exceed the capacity of your iPod by looking at the information showing in the window for each one:
    How to create a Smart Playlist with iTunes
    Syncing Music to iPod
    Syncing selected playlists is just like syncing your whole library only on a smaller scale and more "selectively". When your iPod is is set to sync selected playlists it automatically picks up any changes you made to that playlist in iTunes since you last connected. Anything you added to the playlist will be added to the iPod, anything you deleted from it will be deleted from the iPod. In other words the iTunes playlist and the iPod are kept "in sync".

  • How do I know how much space I have used?

    how do I know how much space I have used?

    Settings > General > About - look for "Capacity" and "Available."
    Go to Settings > General > Usage for a more detailed breakdown.

  • How do I know how much data i'm using?

    How do I know how much data i'm using on my iPad ?

    Your carrier may have an app for that.
    Also Settings > General > Usage > Cellular Network Data should have your stats to date which you can reset at the begininning of each charging period.
    tt2

  • How do I know how much space Im using in iCloud now ?

    How do I know how much space Im using now in the iCloud. I would like to know before I change the storage plan.
    Gale

    Settings/My iCloud/Storage and Backup - Then subtract Available from Total Storage.

  • How do you know how much compression a jpg file is compressed with ?

    Hi there !
    i d like to know how much compression a jpg file is compressed with ? 0 to 12

    i can't open this file JPEGQuality.jsx
    the extension file on the topic says .zip
    i have got an os 10.10 ???
    thanks
    2014-11-28 14:46 GMT+01:00 cuisinerouge . <[email protected]>:
    Thanks !
    i m gonna have a go right now
    >
    2014-11-28 14:43 GMT+01:00 c.pfaffenbichler <[email protected]>:
        how do you know how much compression a jpg file is compressed with ?
    >> created by c.pfaffenbichler
    >> <https://forums.adobe.com/people/c.pfaffenbichler> in *Photoshop General
    >> Discussion* - View the full discussion
    >> <https://forums.adobe.com/message/6969227#6969227>
    >>

Maybe you are looking for