Calamity Lane

Curious Code for Curious Coders

More GServer Goodness

In a previous posting, I demonstrated how to create a telnet server from a Rails application. After having actually used GServer in anger, I can add a few notes to it:

ACCESSING YOUR SERVER REMOTELY

This one took way too long to figure out. Every example I’ve seen online (even the library documentation) will only let you connect from localhost, which seemed even more exceptionally pointless than the stuff I usually do. Most of the sample code runs along these lines:

1
2
3
4
5
6
7
8
9
require 'gserver'

class SomeNewServer < GServer
  ...
end

server = SomeNewServer.new 1234
server.start
server.join

…where “1234” is the port used to access the server. With this setup, you simply cannot access the server from another box, period. Change the following line:

1
server = SomeNewServer.new 1234

…to:

1
server = SomeNewServer.new 1234, 'myserver.example.com'

…to make your new server accessible to the outside world. You can use an IP address in place of the domain name.

On the one hand, I was able to just guess at this parameter, and Ruby’s Principle of Least Surprise came through for me. It’s more secure, as you don’t have to worry about accidentally exposing a massive security hole on your box during development. On the other hand, it would have been nice to have it clearly listed out somewhere. Here’s hoping that this saves some future googler a guessing game.