Socket.setSoTimeOut() i dont get it

setSoTimeout
public void setSoTimeout(int timeout)
throws SocketExceptionEnable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
i dont get what it means when it says block? stop? And when it says it must be vailid prior to entering the block operation where abouts is that?
Thanks

Some Socket methods are designed to read a known number of bytes from an input stream. If those methods read less than the specified number of bytes, they will "block", which means that Socket is incapable of performing any other task until the read method completes. This can tie up system resources by keeping connections open, and might not be something desired. To avoid this, you would set the Socket's timeout value, and after the specified interval, if the Socket is still "blocked", it will timeout. When it times out, it throws an exception, but does not close the Socket or perform any Socket-related shutdown routines; it has not been "stopped". In order to shut down the Socket, you would have to write code to catch the appropriate exception, and explicitly close the Socket in that catch block. The explanation of the Socket's behavior is intended to let you know that the timeout process that happens when you set a timeout value greater than 0 is not designed to perform any resource deallocation or Socket close actions - that responsibility is left up to the programmer to handle or delegate as they see fit.
So basically, a Socket, when attempting to read from an input stream, will not be able to do anything else until that read completes - it "blocks" waiting for the read to complete. If the read does not complete, a method is needed to free up resources that may be associated with that Socket after a certain amount of time has passed (maybe the code is being run in an environment where system thread or connectivity resources are at a premium). By setting a timeout value on a Socket you can achieve this goal, but the responsibility for stopping or closing the Socket so that the appropriate resources are released lies with the programmer using the Socket.
Hope this isn't too incomprehensible; I recommend looking at Sun's tutorials and documentation related to Sockets for somewhat clearer explanations and code examples.
-dSn

Similar Messages

  • I just bought an Apple TV and i have a bose sounddock with a mini jack in the back and and optical cord with a mini adapter on it (so optical cord going into the Apple TV and the mini adapter on the other end going into my bose dock but i dont get sound??

    I just bought an Apple TV and i have a bose sounddock with a mini jack in the back and and optical cord with a mini adapter on it (so optical cord going into the Apple TV and the mini adapter on the other end going into my bose dock but i dont get sound?

    Not all the sound docks accept both analogue and optical on the auxillary input - I don't think the portable ones does but may be wrong - check the user manual.
    As I said earlier all the mini optical (min Toslink) adapter does it make the optical connector fit a smaller socket, it does not convert digital audio to analogue for an analogue only auxillary input.
    AC

  • I bought a cd and downloaded it to my itunes account. I want to burn it to keep one in my car but I dont get that option. how can i burn it from my itunes account?

    I bought a cd and downloaded it to my itunes account.  I want to burn one to keep in my car, but dont get that option. how can i burn it from my itunes account?

    Hello lindsey0315,
    I read your post, and I have linked to an article that will instruct you on how to create CDs with iTunes:
    iTunes 11 for Windows: Create your own CDs and DVDs
    http://support.apple.com/kb/PH12348
    Thank you for contributing to Apple Support Communities.
    Cheers,
    BobbyD

  • I have been trying to upload more music to my iphone 3gs but whenever i try to even click on the artist or name buttons in itune they dont get highlighted or anything all i can do is play music from my phone through itunes ...

    i have been trying to upload more music to my iphone 3gs but whenever i try to even click on the artist or name buttons in itunes they dont get highlighted or anything all i can do is play music from my phone through itunes ... if you know of anything i have done wrong plz tell me how to fix (besides restore)

    Success!! There truly is a light at the end of the tunnel. Apple support really did come through and I am successfully back into my account. Ready to purchase more music. I followed the instructions, with patience I thought I lost, submitted my problem, someone emailed me back within two days and all is now perfect. Thanks again Apple.
    To all the frustrated users out there, don't lose hope!!!

  • Since the last update for my Iphone 4s i dont get text messages when connected to wifi. my wife is getting them. Imessage is switched off on both phones.

    since the 6. version update. of my Iphone 4s My wife was getting my text messages. I found the problem was caused by Imessage when connected to Wifi. I deactivated Imessage on both phones to solve the problem. I now have updated my Iphone to 6.1.1 and i dont get text messages anymore. I have Imessage deactivated on my phone but my wife is getting my text messages again. my wifes phone was not updated to 6.1.1 because the last update lost all her contacts from her phone and we had to but them back in one by one from the outlook list. Her contact are listed in outlook on a seperate list to mine but we can only get my contacts download to her phone. We use the same laptop to sysc phones.
    My Iphone does not download photos to My Pictures anymore. I have to copy them across to a folder. I cant find where it backs them up to.
    I have lost all confidence in Apple now as i was forced to update to 6.1.1 because of 3G reception issues and not reciving calls and now back to spending several hours trying to fix my phone to recieve a basic text message.

    Are you and your wife sharing apple id?
    If you are that is the reason why she is seeing your imessage.
    On both phone go to settings - message - send&receive - make sure the cell is the default.
    You will have to uncheck or remove the apple id.

  • When I receive photo attachment with yahoo(firefix 3.6.3) and I try to open it after clicking download I dont get a choice to open - only to save the photo (doesnt happen with safari but i vastly prefer firefox) - how can i simply open the photo

    using firefox 3.6.3 - generally love the program - when I open an email with a photo attachment (I use mac and yahoo) I click on download the photo and I'm asked to save file -i dont get the option to simply oprn the attahment - i dont want to save - simply open (if I uses safari to double check the problem with same email I do have the choice to open) - do i have some setting wrong - I love firefox but his is really annoying Thanks for your help
    == always happens

    using firefox 3.6.3 - generally love the program - when I open an email with a photo attachment (I use mac and yahoo) I click on download the photo and I'm asked to save file -i dont get the option to simply oprn the attahment - i dont want to save - simply open (if I uses safari to double check the problem with same email I do have the choice to open) - do i have some setting wrong - I love firefox but his is really annoying Thanks for your help
    == always happens

  • How to get reading list in my all my devices and computer (window 7). i have installed ios 6 on iphone and icloud control panel on both PC's (home and office) but i dont get updated reading list on all my devices.

    how to get reading list in my all my devices and computer (window 7). i have installed ios 6 on iphone and icloud control panel on both PC's (home and office) but i dont get updated reading list on all my devices.

    Hi bluegrandpanash,
    Thanks for visiting Apple Support Communities.
    If you backed up your iPhone to iCloud before updating the software, first try the steps under "Restore from an iCloud backup" in this article to recover your data:
    iOS: Back up and restore your iOS device with iCloud or iTunes
    http://support.apple.com/kb/HT1766
    Best Regards,
    Jeremy

  • I can't connect to the itunes store. I have the latest version of itunes on my windows 7 computer. I can connect to itunes from my ipad and ipod but no my windows computer. i dont get any error message, the bar at the top just says accessing itunes.

    I can't connect to the itunes store. I have the latest version of itunes on my windows 7 computer. I can connect to itunes from my ipad and ipod but no my windows computer. i dont get any error message, the bar at the top just says accessing itunes

    Close your iTunes,
    Go to command Prompt -
    (Win 7/Vista) - START/ALL PROGRAMS/ACCESSORIES, right mouse click "Command Prompt", choose "Run as Administrator".
    (Win XP SP2 n above) - START/ALL PROGRAMS/ACCESSORIES/Command Prompt
    In the "Command Prompt" screen, type in
    netsh winsock reset
    Hit "ENTER" key
    Restart your computer.
    If you do get a prompt after restart windows to remap LSP, just click NO.
    Now launch your iTunes and see if it is working now.
    If you are still having these type of problems after trying the winsock reset, refer to this article to identify which software in your system is inserting LSP:
    Apple software on Windows: May see performance issues and blank iTunes Store
    http://support.apple.com/kb/TS4123?viewlocale=en_US

  • HT204291 I have a MBP 13-inch, Mid 2010 and have just upgraded to mountain lion and am trying to connect it to my apple tv however i dont get the air play icon on my mac i have followed all the advise on support anyone able to help??

    I have a MBP 13-inch, Mid 2010 and have just upgraded to mountain lion and am trying to connect it to my apple tv however i dont get the air play icon on my mac i have followed all the advise on support anyone able to help??

    stevie, a third party app called airparrot will give you the pretty much the same as mirroring and forks on Macs too old to mirror.

  • MY iPhone 4 after  being updated to iOS7 will not download or update any apps. When i press the button on my device to download a new app the loading wheel appears then in a few seconds disappears. I dont get a terms and conditions screen or anything.

    MY iPhone 4 after  being updated to iOS7 will not download or update any apps. When i press the button on my device to download a new app the loading wheel appears then in a few seconds disappears. I dont get a terms and conditions screen or anything.

    Ive tried using wifi and 3G seperately. Ive tried restarting the phone. Ive tried restoring it from a backup but none of these have worked yet.

  • I dont get sound for videos, games and music but ringtone still works. When i press volume buttons on side of phone i only get the picture of the nell and no little dots underneath. This is on my iphone 4s and ipad. It happened at the same time.

    I dont get sound for videos, games and music but ringtone still works. When i press volume buttons on side of phone i only get the picture of the nell and no little dots underneath. This is on my iphone 4s and ipad. It happened at the same time.

    Recurring theme with the 4s losing alerts except for the phone ringing.  Most complaints seem to center on the 7.1 upgrade.  The fix is dodgy, putting in a charger, playing a you tube video then pulling out the charger and wiggling it until you get the sound back.  When you get the sound back, the volume buttons start to work again.  Alternate solutions involve cleaning the docking port with a toothbrush, running a pick over the electrodes etc.

  • MDB messages dont get processed from Queues when involving a remote Topic in transaction

    Using WLS 6.1 SP4 on winXP Pro boxes, I have come across a peculiar problem:
              I have several MDBs that process ObjectMessages from queues and forward their payload (wrapped in another new ObjectMessage) to other queues, all of which are located within the same WLS server.
              Right now I'm adding a new MDB that gets messages from a remote Topic with a durable subscription, and forwards the payload to local queues after some processing.
              When the Topic is local as well, there is no problem. But when the Topic is set up in a remote machine, only the MDB that has the remote durable subscription works the way it should. It receives the remote message and forwards it to the corresponding local queue. But then the messages in those local queues dont get processed. The 'Messages Received' count rises and the 'Messages' count stays at 0, as if the messages had been correctly processed and acknowledged, but no onMessage() method is called besides the one from the MDB that has the durable subscription to the remote Topic (I can tell because there's no further processing from the queue those messages get put in). It's as if those messages were simply received and acknowledged without being passed to other MDBs by WLS.
              * All queue MDBs use Required container-managed transaction management and auto-acknowledge
              * All queue MDBs have default durability for their queue subscriptions
              * The topic MDB has a durable subscription stored in a filestore
              * Lookup of the remote Topic is done via JNDI
              Since the processing and forwarding of messages occurs the way it should when everything is local, I am inclined to believe one of two things:
              a) There's some issue with the way WLS treats messages (or even just payloads) when they come from a remote server
              b) WLS is doing something I'm not aware of when propagating a transaction that begins with the delivery of a message from a remote JMS Topic when it involves further forwarding of messages in local JMS Queues.
              Any help will be appreciated.
              regards,
              .munir estevane
              

    Is the durable subscriber forwarder rolling back its transactions?
              That would cause the behavior you describe (eg the message gets
              placed in the queue, but is never made visible). What do
              the pending counts on the destination queue look like?
              Munir Estevane wrote:
              > Using WLS 6.1 SP4 on winXP Pro boxes, I have come across a peculiar problem:
              >
              > I have several MDBs that process ObjectMessages from queues and forward their payload (wrapped in another new ObjectMessage) to other queues, all of which are located within the same WLS server.
              > Right now I'm adding a new MDB that gets messages from a remote Topic with a durable subscription, and forwards the payload to local queues after some processing.
              >
              > When the Topic is local as well, there is no problem. But when the Topic is set up in a remote machine, only the MDB that has the remote durable subscription works the way it should. It receives the remote message and forwards it to the corresponding local queue. But then the messages in those local queues dont get processed. The 'Messages Received' count rises and the 'Messages' count stays at 0, as if the messages had been correctly processed and acknowledged, but no onMessage() method is called besides the one from the MDB that has the durable subscription to the remote Topic (I can tell because there's no further processing from the queue those messages get put in). It's as if those messages were simply received and acknowledged without being passed to other MDBs by WLS.
              >
              > * All queue MDBs use Required container-managed transaction management and auto-acknowledge
              > * All queue MDBs have default durability for their queue subscriptions
              > * The topic MDB has a durable subscription stored in a filestore
              > * Lookup of the remote Topic is done via JNDI
              >
              > Since the processing and forwarding of messages occurs the way it should when everything is local, I am inclined to believe one of two things:
              > a) There's some issue with the way WLS treats messages (or even just payloads) when they come from a remote server
              > b) WLS is doing something I'm not aware of when propagating a transaction that begins with the delivery of a message from a remote JMS Topic when it involves further forwarding of messages in local JMS Queues.
              >
              > Any help will be appreciated.
              >
              > regards,
              > .munir estevane
              

  • Urgent! please help: why socket.setSoTimeout(ms) doesn't work precisely

    I wanted to set timeout for the sockets accepted by server as:
    Socket socket = server.accept();
    socket.setSoTimeout(5);
    Since I want the server to process next request (another thread) as soon as read block happened on the current one, I set the timeout to be extremely short. But it doesn't work. I intentionly blocked my testing client and timed my first .read() method from server. 200 ms actually escaped, no timeout happened. What could be the problem?

    You can't really expect processors to be that fine-grained. There are multiple factors:
    1) other apps are running (such as the OS), consuming processor time as well
    2) processor speed
    3) etc.

  • Socket, setSoTimeout and SocketTimeoutException

    I am experimenting with different Socket.setSoTimeout settings while reading the inputstream with BufferedReader.readLine. I have tried to provoke a SocketTimeoutException while reading a string from the Socket.inputStream.
    I have noticed that if a timeout happens after I have flushed some strings with a BufferedWriter.write, but before I have generated a string with EOL, the BufferedReader.readLine first generates a SocketTimeoutException, and then readLine-method returns the flushed strings even though none of them had a "\n", "\r" or "\r\n".
    Now, what I have not been able to do (or at least was not aware of), is to generate a Timeout before an entire string is read by the Socket.inputStream.
    1. Is it possible that if I write "this is a test\n" that a Timeout could produce (with repetitive BufferedReader.readLine) "this i" and "s a test"?
    2. What would happen if I was using ObjectOutputStream.writeObject and ObjectInputStream.readObject?
    I have looked at the source-code of BufferedReader, but I think I could spend several days to try to understand it. If anyone has any experience or ideas regarding question 1 or 2, feel free to share them.

    Moved topic to:
    http://forum.java.sun.com/thread.jspa?threadID=666967

  • Mac cant see the wifi network if i dont get close enough which was not an issue before

    Hi. I have a macbook pro OSX 10.8.4
    At the office my mac can not see our network router if i dont get close enough.
    This was not an issue before i could directly connect it at my desk. now when i turn the
    computer on i need to take to mac as closest as i can get to the router ( in next room ) wait for connection
    and return to my room. and this way i still can get full signal.
    and also a windows laptop on my desk and even my iphone can find the router and connect with no problem
    at my office.
    any ideas ?

    Hi! It's been a while but here's the latest update on the case.
    (And yeah,I've been struggling until today to find a solution...Danny's personal advice: don't move to Italy if you don't wanna get lost in a Customer Service nightmare...)
    Anyhow, it turned out to be as simple as this:
    1) Create a location dedicated to the home network.
    2) Insert PPPoE user name and password given by ISP.
    3) Connect.
    4) Browse wirelessly.
    ...I feel a little dumb overlooking this option....but, I still have some doubts reg the procedure.
    Why did I have to create a dedicated location?
    Why do I have to use PPPoE rather than DHCP?
    Thanks mate,
    D

Maybe you are looking for