[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

socket recv or gets?

Jamal Soueidan

10/17/2008 7:41:00 AM

Hello there,

I wonder whats the difference between these methods ( gets and recv )

loop {
data = current_client.recv(100)
puts data
}

When I use "gets" instead of recv my socket connection stops and never
print out the message?

Why? :D

Thanks..
--
Posted via http://www.ruby-....

23 Answers

Robert Klemme

10/17/2008 9:30:00 AM

0

On 17.10.2008 09:40, Jamal Soueidan wrote:
> Hello there,
>
> I wonder whats the difference between these methods ( gets and recv )
>
> loop {
> data = current_client.recv(100)
> puts data
> }
>
> When I use "gets" instead of recv my socket connection stops and never
> print out the message?
>
> Why? :D

See documentation. #gets tries to read a line (i.e. until it sees a line
terminator). Also, I believe recv also works with UDP while I am not
sure about gets.

Cheers

robert

Jamal Soueidan

10/17/2008 10:09:00 AM

0

Robert Klemme wrote:
> On 17.10.2008 09:40, Jamal Soueidan wrote:
>> print out the message?
>>
>> Why? :D
>
> See documentation. #gets tries to read a line (i.e. until it sees a line
> terminator). Also, I believe recv also works with UDP while I am not
> sure about gets.
>
> Cheers
>
> robert

Hmm, I looked before at documentation and they wrote...

"A separator of nil reads the entire contents..."

so I did :)

@data = gets()

But my code stops after that and wouldn't continue? even though
gets(nil) is the same, I also tried that, didn't work.
--
Posted via http://www.ruby-....

akl

10/17/2008 10:16:00 AM

0

Jamal Soueidan wrote:

> so I did :)
>
> @data = gets()

in analogy to your recv-Example it should look like:
loop {
      data = current_client.gets
      puts data
}

;)
Andi

Jamal Soueidan

10/17/2008 10:33:00 AM

0

unknown wrote:
> Jamal Soueidan wrote:
>
>> so I did :)
>>
>> @data = gets()
>
> in analogy to your recv-Example it should look like:
> loop {
>       data = current_client.gets
>       puts data
> }
>
> ;)
> Andi

This doesn't work :)

I also tried

while(data = gets)
p data
end

The code doesn't continue :(
--
Posted via http://www.ruby-....

Robert Klemme

10/17/2008 11:24:00 AM

0

On 17.10.2008 12:09, Jamal Soueidan wrote:
> Robert Klemme wrote:
>> On 17.10.2008 09:40, Jamal Soueidan wrote:
>>> print out the message?
>>>
>>> Why? :D
>> See documentation. #gets tries to read a line (i.e. until it sees a line
>> terminator). Also, I believe recv also works with UDP while I am not
>> sure about gets.
>>
>> Cheers
>>
>> robert
>
> Hmm, I looked before at documentation and they wrote...
>
> "A separator of nil reads the entire contents..."
>
> so I did :)
>
> @data = gets()

Look again. http://www.ruby-doc.org/core/classes/IO.ht...

Note, that instead of gets(nil) you can as well use read.

> But my code stops after that and wouldn't continue? even though
> gets(nil) is the same, I also tried that, didn't work.

You need to understand blocking IO: the IO operation blocks until
everything is read. In case of a socket, it will only return if there
was an error or the other party closed the socket. So, you need to
define the protocol in a way that you either know beforehand how much
you need to read (then you can use read(length) or recv(length)) or you
need a separator that you can use to recognize message end (then you can
use gets(separator)).

Kind regards

robert

Anim8rFSK

4/20/2014 3:40:00 PM

0

In article <alpine.LNX.2.02.1404200918120.16015@darkstar.example.org>,
Michael Black <et472@ncf.ca> wrote:

> On Sun, 20 Apr 2014, anim8rFSK wrote:
>
>
>
> > at which point the boss
> >> sticks his foot in it and stammers about Diana's character, then ribs
> >> Steve about getting a C- in algebra interfering with his ability to
> >> submit accurate reports to accounting. I guess my algebra teacher was
> >> right all along about using algebra! Diana gets home and twirls into WW
> >> and uses her tiarrah to activate her magic mirror and inform her fake
> >
> > Hey, they actually used her new power, set up in the RETURN movie,
> > showing this Friday!
> >
> What, she can do math now?

No, silly, rub the red spot until you hallucinate!
>
>
> >> Queen about the situation, who waxes poetic about her dilema and gives
> >> her some vague zen Barbra Streisand about the heart of darkness leading
> >> to light. I'm finding it hard to believe Manta and America set up shop a
> >> few miles away from Paradise Island and never noticed anything!
> >> Meanwhile, at Manta's secret base, Manta goes all medeival on a bullseye
> >> target with a star in middle of a parking lot. Wow, what a bad-ass! As
> >> Steve and Diana fly to wherever it is they are going, Diana repeats how
> >> Manta has unlimited power (huh) and meddles in all sorts of maugtyness
> >> around the world. Steve mentions missisng time in Bermuda Triangle in
> >> the past and that the same thing happened to his father.
> >
> > Worse still, Steve says Manta may have been responsible for shooting his
> > father down (hah hah, since it was Diana) and he's seeking revenge -
> > wait, what? Steve's father was shot down THIRTY FIVE YEARS AGO. How
> > long does he think Manta has been operating down there?
> >
> If WOnder Woman doesn't look a day older, then why might there not be
> other people in the Bermuda Triangle area that were around during WWII and
> haven't aged?

.... fair point, but still an odd thing for Steve to think of. Besides,
in the pilot movie (airing in just 5.5 days) Steve Junior HIMSELF
vanishes in the Bermuda Triangle. I'd think that would be fresher in
his mind ...
>
> >> finds the sub and attaches a mine to it. After it explodes, Manta sets
> >
> > Wait - go back there. Diana just blew up the Nelson Institute for
> > Marine Research submarine SSRN Seaview! With hundreds of crew aboard!
> >
> Clearly subtle commentary on what the producers of WW thought of Irwin
> Allen productions.

This wasn't the VOYAGE studio or network though, which raises questions
....
>
>
> > OUCH! After making sure Steve is OK, WW mentions that stupid zen
> >> bastard crap her fake Queen told her. Later, Charlie shows them footage
> >> of the island exploding and annoucnes the site is no longer suitable,
> >> much to Diana's relief.
> >
> > Because the bomb opened huge dangerous fissures in the ocean floor ...
> > exactly why isn't Paradise Island worried about THAT?
> >
> Isn't that something that happened in "The Neptune Factor"?

Kind of. A seaquake tossed the lab over the edge of the cliff it was
built next too. Same thing happened in the Abyss.

--
Wait - are you saying that ClodReamer was wrong, or lying?

Michael Black

4/20/2014 6:09:00 PM

0

Anim8rFSK

4/20/2014 6:53:00 PM

0

In article <alpine.LNX.2.02.1404201408080.16387@darkstar.example.org>,
Michael Black <et472@ncf.ca> wrote:

> On Sun, 20 Apr 2014, anim8rFSK wrote:
>
>
> >>> Because the bomb opened huge dangerous fissures in the ocean floor ...
> >>> exactly why isn't Paradise Island worried about THAT?
> >>>
> >> Isn't that something that happened in "The Neptune Factor"?
> >
> > Kind of. A seaquake tossed the lab over the edge of the cliff it was
> > built next too. Same thing happened in the Abyss.
>
> I'm surprised anyone else knew about The Neptune Factor.
>
> MIchael

My dad used to own it. :)

--
Wait - are you saying that ClodReamer was wrong, or lying?

Michael Black

4/20/2014 9:14:00 PM

0

Obveeus

4/20/2014 9:34:00 PM

0



On 4/20/2014 5:14 PM, Michael Black wrote:
> On Sun, 20 Apr 2014, anim8rFSK wrote:
>
>> In article <alpine.LNX.2.02.1404201408080.16387@darkstar.example.org>,
>> Michael Black <et472@ncf.ca> wrote:
>>
>>> On Sun, 20 Apr 2014, anim8rFSK wrote:
>>>
>>>
>>>>>> Because the bomb opened huge dangerous fissures in the ocean floor
>>>>>> ...
>>>>>> exactly why isn't Paradise Island worried about THAT?
>>>>>>
>>>>> Isn't that something that happened in "The Neptune Factor"?
>>>>
>>>> Kind of. A seaquake tossed the lab over the edge of the cliff it was
>>>> built next too. Same thing happened in the Abyss.
>>>
>>> I'm surprised anyone else knew about The Neptune Factor.
>>>
>>> MIchael
>>
>> My dad used to own it. :)
>>
> I went and saw it when it first came out, I guess there must have been
> something in the review in the local paper to make it sound good. It
> may have been the first non-kid's movie that I went to by myself, I
> certainly hadn't seen that many movies at all in a theatre before that.
>
> Maybe because it was science fiction, and maybe because I was just old
> enoguh to go see it, is the reason I saw it. I don't remember that much
> about it, and I gather it never did that well.

Another possibility is that the reviews in the paper made it sound
horrible, but you still wanted to go...but the film looked so bad that
no adult was willing to suffer through it just to take you, so they
instead let you see your first non-kid's film on your own.

This scenario is how PG-13 horror films get most of their audience.
Parents can go see the higher end animated films with their kids and
find some enjoyment. Parents can go and see superhero shows with their
kids and still find some enjoyment. Parents can go and see supernatural
shows about witches, dragons, teens with special powers, etc... and
still find some enjoyment. Then, along comes a PG-13 horror film and
every parent knows it will suck (it doesn't have an R rating in a genre
that should almost always have an 'R' rating to be good). That is the
moment the parent decides that just maybe it is time to let their kid go
to a film with his/her friends unattended.