title: Break an infinite loop
body: <p>i have an infinite loop something like that:</p>
  
  <pre><code>while(true) {
      //do something
  }
  </code></pre>
  
  <p>I would like to be able to break the loop using a key for exaple escape key. I think it could be done using events but as i am new to java i cant do that. 
  Can anyone help me? Thank you in advance!</p>
  
  <p>In the while loop the program reads a value from usb and then send it over the network using sockets. My program is the server and sends bytes to a client. I want to be able to stop that server with a key!</p>
  
  <hr>
  
  <p>In the while loop the program reads a value from usb and then send it over the network using sockets. My program is the server and sends bytes to a client. I want to be able to stop that server with a key! </p>