Newbie dumb question regarding GServer

M

Mike Pence

Hello all,

Great to be here. Ruby is re-igniting my love of software development.

I am running this code:

require 'gserver'

#
# A server that returns the time in seconds since 1970.
#
class TimeServer < GServer
def initialize(port=3D10001, *args)
super(port, *args)
end
def serve(io)
io.puts(Time.now.to_i)
end
end

# Run the server with logging enabled (it's a separate thread).
server =3D TimeServer.new
server.audit =3D true # Turn logging on.
server.start

And getting this output:

[Wed Sep 28 12:40:24 2005] TimeServer 127.0.0.1:10001 start
[Wed Sep 28 12:40:28 2005] TimeServer 127.0.0.1:10001 stop

Why is the server stopping?

Thanks,
Mike Pence
 
J

James Edward Gray II

Hello all,
Howdy.

Great to be here. Ruby is re-igniting my love of software development.

Glad to hear it.
I am running this code:

require 'gserver'

#
# A server that returns the time in seconds since 1970.
#
class TimeServer < GServer
def initialize(port=10001, *args)
super(port, *args)
end
def serve(io)
io.puts(Time.now.to_i)
end
end

# Run the server with logging enabled (it's a separate thread).
server = TimeServer.new
server.audit = true # Turn logging on.
server.start

We should probably update that example in the documentation. I'm
sure we could do better.
And getting this output:

[Wed Sep 28 12:40:24 2005] TimeServer 127.0.0.1:10001 start
[Wed Sep 28 12:40:28 2005] TimeServer 127.0.0.1:10001 stop

Why is the server stopping?

GServer runs in its own Threads. But your main program is just
starting it and then ending. You need to ask it to wait on the
server. Add the following line at the end of your script:

server.join # wait on server...

Hope that helps. Welcome to Ruby!

James Edward Gray II
 
E

Edward Faulkner

--MGYHOYXEY6WxJCY8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Why is the server stopping?

If your main threads reaches the end, the program will exit. I think
you need to call GServer#join to make the main thread wait.

regards,
Ed

--MGYHOYXEY6WxJCY8
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDOtpynhUz11p9MSARAhIEAJ4mz3RKsMc6Hecv7AiCMdimarrUYwCg34Vj
PoWplggCCXOM2kckBghC6Xw=
=V+zf
-----END PGP SIGNATURE-----

--MGYHOYXEY6WxJCY8--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top