Telnet by socket

Hi
i am trying to telnet by ruby.. i went through google. but i am bit
confused.
so i need bit help

require 'socket'
host = 'localhost'
port = 5555
socket = TCPSocket.open(host,port)
send = socket.send("recover BD-1",0)
response = socket.sead
print response

basically, if i do from command line

telnet localhost 5555
OK Server
recover BD-1 : then i will type this

and then telnet will output
OK

so i need to get that OK

but that socket is not doing anything

Can some one help me out please

···

--
Posted via http://www.ruby-forum.com/.

Hi
i am trying to telnet by ruby.. i went through google. but i am bit
confused.
so i need bit help

require 'socket'
host = 'localhost'
port = 5555
socket = TCPSocket.open(host,port)
send = socket.send("recover BD-1",0)
response = socket.sead

                     ^^^^
typo

···

Am 11.10.2012 11:42, schrieb Ferdous ara:

print response

--
<https://github.com/stomar/&gt;

Ferdous ara wrote in post #1079397:

Hi
i am trying to telnet by ruby.. i went through google.

Then you should have found Net::Telnet which is part of the ruby
standard library.

But then maybe you don't actually want telnet; what you want is to
communicate over a TCP socket.

In that case, beware that the protocol will probably require you to end
the command with \r\n, or at least \n, which you are not sending at the
moment.

···

--
Posted via http://www.ruby-forum.com/\.

HI
i found the solution i had to put

sock.puts "recover BD-1\r\n"
response = sock.read

i had to put \r\n
i guess its specifiq to environment .

but only problem is ,

its giving me 2 out put

OK Server
Ok

but how will just take the last output which is OK?

do i have to take the value as array ??

thanks

···

--
Posted via http://www.ruby-forum.com/.

Hi
no the first response is :

OK Server

which is, when you connect to the telnet

but I need the 2nd one

OK

···

--
Posted via http://www.ruby-forum.com/.

It sounds like it's receiving and responding to \r and then \n. Just
take the first output.

···

On Sat, Oct 13, 2012 at 6:39 AM, Ferdous ara <lists@ruby-forum.com> wrote:

HI
i found the solution i had to put

sock.puts "recover BD-1\r\n"
response = sock.read

i had to put \r\n
i guess its specifiq to environment .

but only problem is ,

its giving me 2 out put

OK Server
Ok

but how will just take the last output which is OK?

do i have to take the value as array ??