# Socket connection to the Tor server

**URL:** <https://www.ruby-forum.com/t/socket-connection-to-the-tor-server/158508>\
**Category:** Ruby\
**Created:** [January 24, 2009, 12:42am UTC](https://www.ruby-forum.com/t/socket-connection-to-the-tor-server/158508 "2009-01-24T00:42:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camilleroux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@camilleroux](https://www.ruby-forum.com/u/camilleroux)\
**Post date:** [January 24, 2009, 12:42am UTC](https://www.ruby-forum.com/t/socket-connection-to-the-tor-server/158508/1 "2009-01-24T00:42:43Z")

</div>

Hi,

I’d like to code a script able to connect to the Tor server. Find above  
the command line script. I’d like to do the same in ruby. I tried using  
TCPSocket, Net::Telnet… no way.

Thank you  
Camille

SHELL SESSION:  
camille$ telnet 127.0.0.1 9051  
Trying 127.0.0.1…  
Connected to localhost.  
Escape character is ‘^]’.  
authenticate  
250 OK

…

quit  
250 closing connection  
Connection closed by foreign host.

---

<div class="post-metadata">

**Author:** ![camilleroux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@camilleroux](https://www.ruby-forum.com/u/camilleroux)\
**Post date:** [January 24, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/socket-connection-to-the-tor-server/158508/2 "2009-01-24T15:35:36Z")

</div>

I found finally how to do that. I forgot to write \r\n at each end of  
line.  
Here the code:

require ‘net/telnet’

t = TCPSocket.new(“localhost”,‘9051’)  
t.puts(“authenticate\r\n”)  
puts t.gets  
#…  
t.puts(“quit\r\n”)  
puts t.gets

Camille R. wrote:

> Hi,
> 
> I’d like to code a script able to connect to the Tor server. Find above  
> the command line script. I’d like to do the same in ruby. I tried using  
> TCPSocket, Net::Telnet… no way.
> 
> Thank you  
> Camille
> 
> SHELL SESSION:  
> camille$ telnet 127.0.0.1 9051  
> Trying 127.0.0.1…  
> Connected to localhost.  
> Escape character is ‘^]’.  
> authenticate  
> 250 OK
> 
> …
> 
> quit  
> 250 closing connection  
> Connection closed by foreign host.
