How to interrupt SSLServerSocket.accept()???

Hi all,
I have created a simple SSL Server socket, and I called 'accept()' in a separate thread, however, this method cannot be interrupted with Thread.interrupt(). It just blocks and stays that way. For non-SSL sockets, I know I can use channels, but I could not find the SSL-equivalent implementation.
Any ideas how to imlement an interruptible SSL server socket?

There is no SSLServerSocketChannel apart from my product at http://www.telekinesis.com.au, but you only need to set a timeout on the SSLServerSocketChannel. This will cause accept() to throw a SocketTimeoutException, and every time it does it can inspect the Thread.isInterrupted() flag. How long the timeout should be is up to you, i.e. how quickly you need the interrupt to take effect.

Similar Messages

  • HT2731 how can my computer accept cookies from itunes music store

    how can my computer accept cookies from itunes music store

    Well on a Mac, you enable cooks in your Safari browser....
    But you're on Windows?

  • I have 2 email addresses on the phone. How come only one accepts a alert tone. When I receive an email from 2nd email it does not notify me of its arrival. What am I doing wrong

    I have 2 email addresses on the phone. How come only one accepts a alert tone. When I receive an email from 2nd email it does not notify me of its arrival. What am I doing wrong?

    Each email account can have its own alert or notification settings.
    Settings > Notifications > Mail > tap on each account and set the alerts you want.

  • SSLServerSocket accept() Denial Of Service

    Working on a small server application using SSLServerSocket to accept() incoming connections, it seems that incomplete SSL negotiation can completely block incoming connections. It seems that each un-negotiated connection occupies one backlog slot - so once you have 50 or so connections that haven't yet completed negotiations no new users are able to connect. These incomplete connections don't seem to time out by default either.
    Is there any easy way to change this in my code so that SSL negotiation must be completed within 10 seconds or it fails?

    Suffice for what? I don't understand the question.
    Maybe you still don't understand the issue here. I stated it above in the first reply. The original poster above is mistaken in his contention. SSLServerSocket.accept() doesn't do any I/O itself. Specifically it doesn't perform the SSL handshake. So there is no way for one rogue client to block the server's accept loop unless something else in the accept loop performs I/O. For example, creating ObjectInputStreamsor ObjectOutputStreams. Note that in your case the constructor of the Connection object runs in the accept loop, not in the new thread. If the new thread does all the I/O on the accepted socket, only the new thread can be blocked by a rogue client. So all you have to do is ensure that condition.
    To avoid the rogue affecting that thread, set a shortish timeout and call startHandshake(): if you get any exception, close the socket and forget about it.

  • How to Make JTextField Accept Only Specific Numbers?

    Hello There
    I've made 3 JTexfields That accepts only Numbers
    But I Want To Make Them Accpets Numbers only from 1 to 12
    and if the number is greater than 12 they don't accept it?
    another Thing That I've Set Their Columns To 2 meaning that i want the user to enter only two numbers
    but yet the user can enter many numbers how would i restrict entering numbers to only two numbers?
    here's my code:
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.text.*;
      public class ManyText extends JFrame{
           public static void main(String[]args){
           JTextField[ ] text = new JTextField[3];
           JButton button=new JButton("Press");
        for(int i = 0; i < text.length; i++)
         text[i] = new JTextField(3);
         for(int i = 0; i < text.length; i++){
         text.setColumns(2);     
    text[i].setDocument(new PlainDocument(){
    public void insertString(int offs, String str,
    AttributeSet a) throws BadLocationException{
    if("0123456789".indexOf(str) < 0)
    java.awt.Toolkit.getDefaultToolkit().beep();
    return;
    super.insertString(offs, str, a);
         JFrame f=new JFrame();
         f.setSize(200,200);
         f.setLayout(new FlowLayout());
         f.add(text[0]);
    f.add(text[1]);
    f.add(text[2]);     
         f.setVisible(true);     

    ejp wrote:
    Actually I would suggest you're using the wrong control. I would use a JComboBox or a JSpinner for this.I suggested he use a JSpinner 1-2 threads ago. Maybe if he hears it enough, he'll believe it.

  • After os7 installation, iCLOUD dosen't work,because T&C terms server not available;how access this to accept?

    I have installed os7.04,but can not use  iCloud, because it says I must accept terms and conditions for iCloud, but when I try to do this, the iPAD says "UNABLE TO CONNECT TO SERVER". How is this problem overcome?

    Try deleting the account and then logging in again. (Settings > iCloud, scroll down and hit "Delete Account")
    Providing you are using the same account details and not changing to another account, when you delete your account, all the data that is synced with iCloud will also be deleted from the device (but not from iCloud), but will be synced back to your device when you login again.
    Some users have found that logging into the ‘Find my friends’ app and accepting the terms and conditions from there has helped.
    Others have found they can accept these terms and conditions by signing in from a computer.
    Some have found that restrictions (settings > general > restrictions) have caused a problem being able to accept the terms and conditions.

  • How to interrupt an funtion call and continue the followed code?

    for example, the code:
    public class A{
    public static void main(String[] args){
    int i = 0;
    method1();
    system.out.println("exit");
    public void method1(){
    int j = 0;
    while(true){
    j +=1;
    there is a error in method1(), so the call the method1( ) in main() will make an error.
    how can i interrupt this funtion call and continue the followed code?

    in actually, I can not control the method1(), that's
    an remote object function.
    So I can not add exception in methoes().Then in your main method catch whatever "Error" your method1 is throwing.

  • How to Interrupt an Unblocked Thread

    Consider the following code:
    public class MyThread extends Thread {
      public void run() {
        //long operation, might NOT be a blocking one, say
       long lineno = 1;
       System.out.println(" Line Number: " + lineno++);
       System.out.println(" Line Number: " + lineno++);
       System.out.println(" Line Number: " + lineno++);
        :   //say some 1000+ such LOC is there. i.e there's no loop/blocking etc
       System.out.println(" Line Number: " + lineno++);
    in some other class
    MyThread obj = new MyThread();
    obj.start();..at some later point, I want to terminate the (long time consuming) operation which is being perfomred by thread (obj) ...
    will the following code work?
    obj = null;What exactly the above code will do to the thread (obj)?
    I know there's one method
    obj.interrupt();but AFA my understanding with this method is that it works best if we have some kind of loops in our run method,
    so that we can periodically check the status whether thread is being interrupted or not, or something similer.
    So how can we interrupt/terminate such thread??

    You cannot safely, forcibly stop a running thread.For code in original post (by vijaywadnere) .stop() should work
    yes it's deprecated and bad idea in general, but it will do
    consider example
    public static void main(String[] args) {
              final Thread obj = new Thread() {
                     public void run() {
                       //long operation, might NOT be a blocking one, say
                      long lineno = 1;
                      while(true){                                   
                      System.out.print(" . " + lineno++);                 
              Thread stopper = new Thread(obj) {
                     public void run() {
                          try {
                             sleep(100);
                             obj.interrupt();
                             System.out.println("\ninterrupt");
                             sleep(100);
                             obj.stop();
                             System.out.println("\nstop");
                        } catch (InterruptedException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
              System.out.println(" obj");
              obj.start();
              System.out.println(" stopper");
              stopper.start();
    }

  • How-to interrupt a hanging methodcall

    I wonder if someone from you now, how
    one can interrupt a method while it is hanging for some
    reason.
    This is the problemdescription is as following:
    If the method has longer then 10 seconds, it needs to be interrupted.
    Any ideas?
    Thanx, nils

    Thanx for your code. But the problem is extended:
    I should get a value from the "sort-of" server. So I did the following:
    public class Main
         public static void main(String[] args)
              Client c = new Client();
              Server s = new Server();
              ControlThread ct = new ControlThread(s,c, 100);
              ct.run();
    * This class gets a server and a client. The
    * client needs a value that is returned by the server.
    * But the server can hang while evaluating that value, so
    * the ControlThread has a timeout thread that bypasses that
    * call if the timeout occures.
    * @author n_birkeland
    class ControlThread{
          * @param Server this is the server that has a method that can hang
          * @param Client this client needs a value from the server
          * @param timeout this is the time the control waits until it
          * bypasses the call to the client
         ControlThread(Server s, Client c, int timeout){
              this.s = s;
              this.c = c;
              this.timeout = timeout;
         public void run(){
              try{
                   Thread invoker = new Thread(){
                        public void run(){
                             value = s.get();
                             doneWork();
                   Thread timer = new Thread(){
                        public void run(){
                             try{
                                  sleep(timeout);
                             }catch(Exception e){;}
                             finally{
                                reachedTimeout();                         
                   invoker.start();
                   timer.start();
                   // wait, until one flag is set to true:
                   while( isTimeoutReached!=true && isWorkDone!=true ){
                        // busy waiting...
                   System.err.println("exited busy waiting: isTimeoutReached="+isTimeoutReached+" isWorkDone="+isWorkDone);
                   if(!isWorkDone){
                        value = -1;
                   c.set(value);
                   invoker.interrupt();
                   timer.interrupt();
              }catch(Exception e){
                   System.err.println(""+e);                    
                   c.set(-1);
         synchronized void doneWork(){
              isWorkDone = true;
              System.out.println("done work: isTimeoutReached="+isTimeoutReached+" isWorkDone="+isWorkDone);          
         synchronized void reachedTimeout(){
              isTimeoutReached = true;
              System.out.println("reached timeout: isTimeoutReached="+isTimeoutReached+" isWorkDone="+isWorkDone);          
         int value = 0;
         boolean isWorkDone = false;
         boolean isTimeoutReached = false;
         final int timeout;
         final Server s;
         final Client c;
    class Server{
         final int HANG_TIME = 300;
         int get(){
              try{
                   System.out.println("server is going to sleep...");
                   Thread.sleep(HANG_TIME);
              }catch(Exception e){;}     
              return 1987234; // some fancy value
    class Client{
         void set(int value){
              System.out.println("Got value from server: "+value);
    }

  • How to interrupt running subvi with global variation

    Hi,all
       I want to use global variation STOP to interrupt the running VI at anytime, but the subVI must be running until executing the WHILE. I knew when one action is  operated in the EVENT case, the other action will not be iperated. My question is how to solve the problem without  POP subVI and the DATA transmitted to MAIN panel. Give me a suggestion, THKS!
      Lioncsu  
    Attachments:
    Main VI.jpg ‏43 KB
    Sub VI.jpg ‏41 KB

    Hi Lioncsu,
          In Main, when a Start event occurs, the Value of Stop (False?) is immediately written to the Global (once), and SubVI starts running.  The Start event case won't complete - or write another value to the Global - until the SubVI is done.  I haven't run this, but I think pressing Stop may cause the SubVI to run (again) - for one iteration! 
    Attached is a simple VI which uses two loops - one to handle GUI events (the buttons) and one to start a while loop.  Maybe you can replace the while-loop with your SubVI?
    Hope it helps!
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
    Attachments:
    Notifiers.vi ‏51 KB

  • How to make OAM accept SAML Assertion?

    Hi folks,
    I need to make OAM accept SAML Assertion. We have a Layer7 appliance called SSG (Secure Span Gateway) which protects web resources and generates SAML assertion. I need to find out whether OAM can accept the SAML Assertion sent by SSG appliance to authenticate and authorize access.
    Any help is appreciated.
    Thank you, Roman

    Hi idmgod,
    Thanks for the post. Rather interesting! Correct me if I'm wrong here, but this is how this should work:
    1. The simpleSAMLphp (configured to support php w extensions, connect and authenticate/authorize against ldap server in my case, etc) sits in front of OAM, and accept the SAML Assertion
    2. It then creates an obSSOCookie (just like the WebGate does), and sends it to OAM
    3. OAM checks obSSOCookie and based on the cookie data (user DN, shared secret key, etc) allows access to a protected resource
    Does this sound right?
    Roman

  • File more than 100mb - so how to reduce into acceptable sizes

    subscribed to convert pdf to MS word BUT pdf file greater than 100mb and so refused !
    How to convert file into acceptable parts thereof ...

    Hi acrpdf,
    You would need Acrobat to split the PDF into smaller parts (and if you had Acrobat, you could save directly to Word format by choosing File > Save as Other > Microsoft Word).
    If you'd like, you could try Acrobat free for 30 days. For more information, see www.adobe.com/products/acrobat.html.
    Best,
    Sara

  • How should i protect accept() method from TooManyOpenFiles?

    I am calling accept() method assuming it will always work, considering it might result in NULL, but i've noticed in some situations the accept will fail and result in a CPU problem because it fails and since i did not do anything with the failure the key might still be valid and it tries to accept over and over again.
    What is the right thing to do here - should i surround with try-catch and it will not attempt to accept the connection again?
            SocketChannel channel = ((ServerSocketChannel) key.channel()).accept();
            if (channel != null)
                if (!isApprovedClient(channel))
                    channel.close();
                    channel = null;
                    rejectedClients++;
                    return;
                acceptedClients++;
                channel.configureBlocking(false);
                BasicContext context = onClientAccept(channel);
                context.setCurrentSocket(channel);
                context.setEstablishTime();
                channel.register(selector, SelectionKey.OP_READ, context);
                log.log(Level.FINER, "Added main-channel {0}", channel.socket().getInetAddress());
            }

    I am calling accept() method assuming it will always work, considering it might result in NULL, but i've noticed in some situations the accept will failFail how?
    and result in a CPU problemWhat CPU problem?
    because it fails and since i did not do anything with the failure the key might still be validWhat key? The key of the ServerSocketChannel? It is valid until you close or deregister it. Nothing to do with accept failures.
    and it tries to accept over and over again.If the accept fails there is no SocketChannel to leak/to be closed.

  • TS1459 how to make computer accept cookies with iTunes store

    I made a new apple id and itunes will not allow me to sign in unless i make the computer accept cookies from the itunes store, which i do not know how to do. please help. thanks.

    I am having this problem as well. Anyone?

  • How can you auto-accept Video Calls in Messages.app

    In Ichat there used to be a way to select a user and under "alerts" (which is no longer a perference option in messages) choose to auto-accept video calls from that person.
    Is there a way to set up Messages to auto acccept video calls? It was great for when I wanted to check in on my puppy.
    Thanks!

    HI,
    In the normal setting of Messages this is no longer possible.
    I would use here to ask for the feature back
    http://www.apple.com/feedback/ichat.html
    The page was never very good at keeping up to date with iChat version numbers so type your specs into the Free Text area.
    It might be possible to copy the AppleScript that did this  and make a copy and remove the non Video bits  and use it from the Dock.
    10:06 pm      Tuesday; November 26, 2013
      iMac 2.5Ghz 5i 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

Maybe you are looking for

  • Need to Find Total number of InfoPart form in our Web application

    Hello, We have to find total number of Infopath forms in our web application. IS there any Power sheell Scripts or anuthing which can output the Infopath Forms location and file count . Thanks Kundan

  • To redirect the Enterprise portal logon page

    Hi all, Due to a certain requirement from the client, I need to redirect the logon page, immediately after the user authentication in portal. At present once the user key in the credentials, it is taken to the portal home page http://...../irj/portal

  • How to execute  the CONNECT command in sql

    Hi , I am using DB2 database and I need to execute the sql statement CONNECT TO Database user username USING password. Can anyone tell me how to execute this query in java. I tried this by using executeQuery but it was giving a sexception somtehing a

  • Triggering an event when writing to Database

    Hi, Does anyone knows a way to trigger some kind of event (some program / function) when a specific standard table changes? Thanks, Doron Oded.

  • Javax.sql.rowset.serial.SerialBlob cannot be cast to oracle.sql.BLOB

    Hi there, I'm facing this exception. My code: final ReportTemplateAttachment rta = new ReportTemplateAttachment(); FileBlob fb = new FileBlob(); fb.setContentType(attachmentDto.getContentType().getValue()); fb.setCreationDate(sysDate); fb.setCreation