[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

create server

Vince Forgetta

4/14/2008 6:05:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hi all,

I am interested in using GServer but the server hangs after ~5-10 attempts
(per max connections to allow). Example code I used is from Peter Coopers
book, Beginning Ruby From Novice to Professional:

http://www.springerlink.com/content/ph5611n...

Is this normal?

Thanks.

Vince

5 Answers

Vince Forgetta

4/14/2008 6:16:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Figured it out.

I need to sleep between successive calls to TCPSocket.new (see simple
example below):

require 'socket'
for i in 0..20
session = TCPSocket.new('localhost', '1234')
session.puts "test"
dat = session.gets
p dat
session.close
sleep 0.5
end

Using 'sleep 0' cause the server to hang. Is there a way around this?

Vince



On Mon, Apr 14, 2008 at 2:05 PM, Vince Forgetta <forgetta@gmail.com> wrote:

> Hi all,
>
> I am interested in using GServer but the server hangs after ~5-10 attempts
> (per max connections to allow). Example code I used is from Peter Coopers
> book, Beginning Ruby From Novice to Professional:
>
> http://www.springerlink.com/content/ph5611n...
>
> Is this normal?
>
> Thanks.
>
> Vince
>

hemant

4/14/2008 6:46:00 PM

0


On Tue, 2008-04-15 at 03:16 +0900, Vince Forgetta wrote:
> Figured it out.
>
> I need to sleep between successive calls to TCPSocket.new (see simple
> example below):
>
> require 'socket'
> for i in 0..20
> session = TCPSocket.new('localhost', '1234')
> session.puts "test"
> dat = session.gets
> p dat
> session.close
> sleep 0.5
> end
>
> Using 'sleep 0' cause the server to hang. Is there a way around this?
>

Perhaps then you should paste server code, rather than client code.



Vince Forgetta

4/14/2008 6:55:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Sorry, here is the code:

require 'gserver'
class HelloServer < GServer
def serve(io)
line = io.gets
io.puts("#{line.chomp}")
end
end
server = HelloServer.new(1234, '127.0.0.1', 1)
server.audit = true
server.start
server.join

On Mon, Apr 14, 2008 at 2:46 PM, hemant kumar <gethemant@gmail.com> wrote:

>
> On Tue, 2008-04-15 at 03:16 +0900, Vince Forgetta wrote:
> > Figured it out.
> >
> > I need to sleep between successive calls to TCPSocket.new (see simple
> > example below):
> >
> > require 'socket'
> > for i in 0..20
> > session = TCPSocket.new('localhost', '1234')
> > session.puts "test"
> > dat = session.gets
> > p dat
> > session.close
> > sleep 0.5
> > end
> >
> > Using 'sleep 0' cause the server to hang. Is there a way around this?
> >
>
> Perhaps then you should paste server code, rather than client code.
>
>
>
>

Vince Forgetta

4/16/2008 1:42:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Solved my problem. Used select instead of threads to implement the server.
Got the code from "The Ruby Programming Language". What a great book!

Vince

On Mon, Apr 14, 2008 at 2:54 PM, Vince Forgetta <forgetta@gmail.com> wrote:

> Sorry, here is the code:
>
> require 'gserver'
> class HelloServer < GServer
> def serve(io)
> line = io.gets
> io.puts("#{line.chomp}")
> end
> end
> server = HelloServer.new(1234, '127.0.0.1', 1)
> server.audit = true
> server.start
> server.join
>
> On Mon, Apr 14, 2008 at 2:46 PM, hemant kumar <gethemant@gmail.com> wrote:
>
> >
> > On Tue, 2008-04-15 at 03:16 +0900, Vince Forgetta wrote:
> > > Figured it out.
> > >
> > > I need to sleep between successive calls to TCPSocket.new (see simple
> > > example below):
> > >
> > > require 'socket'
> > > for i in 0..20
> > > session = TCPSocket.new('localhost', '1234')
> > > session.puts "test"
> > > dat = session.gets
> > > p dat
> > > session.close
> > > sleep 0.5
> > > end
> > >
> > > Using 'sleep 0' cause the server to hang. Is there a way around this?
> > >
> >
> > Perhaps then you should paste server code, rather than client code.
> >
> >
> >
> >
>

Daniel Finnie

4/16/2008 9:59:00 PM

0

Hi,

I'm glad you solved your problem, I just had two comments:

- "#{line.chomp}" is equivalent to line.chomp.
- sleep 0 by definition sleeps forever:
puts "A"
sleep 0
puts "B"

B is never written

Dan

On Wed, Apr 16, 2008 at 9:41 AM, Vince Forgetta <forgetta@gmail.com> wrote:
> Solved my problem. Used select instead of threads to implement the server.
> Got the code from "The Ruby Programming Language". What a great book!
>
> Vince
>
>
>
> On Mon, Apr 14, 2008 at 2:54 PM, Vince Forgetta <forgetta@gmail.com> wrote:
>
> > Sorry, here is the code:
> >
> > require 'gserver'
> > class HelloServer < GServer
> > def serve(io)
> > line = io.gets
> > io.puts("#{line.chomp}")
> > end
> > end
> > server = HelloServer.new(1234, '127.0.0.1', 1)
> > server.audit = true
> > server.start
> > server.join
> >
> > On Mon, Apr 14, 2008 at 2:46 PM, hemant kumar <gethemant@gmail.com> wrote:
> >
> > >
> > > On Tue, 2008-04-15 at 03:16 +0900, Vince Forgetta wrote:
> > > > Figured it out.
> > > >
> > > > I need to sleep between successive calls to TCPSocket.new (see simple
> > > > example below):
> > > >
> > > > require 'socket'
> > > > for i in 0..20
> > > > session = TCPSocket.new('localhost', '1234')
> > > > session.puts "test"
> > > > dat = session.gets
> > > > p dat
> > > > session.close
> > > > sleep 0.5
> > > > end
> > > >
> > > > Using 'sleep 0' cause the server to hang. Is there a way around this?
> > > >
> > >
> > > Perhaps then you should paste server code, rather than client code.
> > >
> > >
> > >
> > >
> >
>