title: Add SSL to a connection
body: <p>How do you secure a socket with SSL in Ruby when you need to communicate over plaintext first?</p>
  
  <p>I can't use <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL/SSL/SSLServer.html" rel="noreferrer"><code>OpenSSL::SSL::SSLServer</code></a> because it's the client's responsibility to request an SSL connection first</p>
  
  <p>To put a long story short, I am attempting to implement RFC3207, where the client sends the keyword "STARTTLS", and then an SSL connection is created.</p>
  
  <p>My question is "How do I create the SSL connection after the server has sent '220 OK'?"</p>
  
  <p>I know I can use <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/openssl/rdoc/OpenSSL/SSL/SSLSocket.html" rel="noreferrer"><code>OpenSSL::SSL::SSLSocket</code></a> on the client-side, but I have no idea what to do on the server-side</p>
  
  <p>If you know how to do this in a language other than Ruby, just post the code and I'll translate it, I've been working on this for about 8 hours and I need everything I can get</p>
  
  <p>I have asked in #ruby-lang, but with no avail, and I have tried wrapping Socket objects in SSLSockets on the server and client at the same time, but that isn't working either</p>
  
  <p>In short, I'm very stuck, I need all the help I can get</p>