M
Mohnish J.
Hi,
I am trying to build a chat application purely using Ruby. I have looked
at the example on http://www.rubyinside.com/advent2006/10-gserver.html .
The code in the example doesn't seem to be working for me. On running
the ruby script on the terminal, and connecting to the url:
http://localhost:1234 in my browser, I indefinitely encounter a
"Transferring data from localhost..." message.
Here 1234 is the port number used in the example provided. I am not able
to figure out what is the reason behind my unsuccessful run. May be I
need to specify something in the command line while executing the script
or I am supposed to start the chat(input output) through some other
place(probably the browser). I am not able to figure out what exactly to
do. Could you please help me out on this?
I am running the chat server code pretty much unmodified. I am running
the web service and the chat server on the same host.
I was able to partially get the code working for me upto the point where
the loop starts. The modified code which worked for me upto a certain
point is given below.
require 'gserver'
class BasicServer < GServer
def initialize(*args)
super(*args)
# Keep an overall record of the client IDs allocated
# and the lines of chat
@@client_id = 0
@@chat = []
end
def serve(io)
# io.puts("Hello world!")
# Increment the client ID so each client gets a unique ID
@@client_id += 1
my_client_id = @@client_id
my_position = @@chat.size
# io.puts(@@chat.size)
# Give the total number of people who are currently on chat.. for
e.g. 0 => 1 person on chat
# Leave a message on the chat queue to signify this client
# has joined the chat
@@chat << [my_client_id, ""]
# io.puts(@@chat)
end
end
server = BasicServer.new(1234)
server.start
#sleep 120
#server.shutdown
Hope you could give me some insights on what could be going wrong from
my end.
Thanks a lot for your time!!
I am trying to build a chat application purely using Ruby. I have looked
at the example on http://www.rubyinside.com/advent2006/10-gserver.html .
The code in the example doesn't seem to be working for me. On running
the ruby script on the terminal, and connecting to the url:
http://localhost:1234 in my browser, I indefinitely encounter a
"Transferring data from localhost..." message.
Here 1234 is the port number used in the example provided. I am not able
to figure out what is the reason behind my unsuccessful run. May be I
need to specify something in the command line while executing the script
or I am supposed to start the chat(input output) through some other
place(probably the browser). I am not able to figure out what exactly to
do. Could you please help me out on this?
I am running the chat server code pretty much unmodified. I am running
the web service and the chat server on the same host.
I was able to partially get the code working for me upto the point where
the loop starts. The modified code which worked for me upto a certain
point is given below.
require 'gserver'
class BasicServer < GServer
def initialize(*args)
super(*args)
# Keep an overall record of the client IDs allocated
# and the lines of chat
@@client_id = 0
@@chat = []
end
def serve(io)
# io.puts("Hello world!")
# Increment the client ID so each client gets a unique ID
@@client_id += 1
my_client_id = @@client_id
my_position = @@chat.size
# io.puts(@@chat.size)
# Give the total number of people who are currently on chat.. for
e.g. 0 => 1 person on chat
# Leave a message on the chat queue to signify this client
# has joined the chat
@@chat << [my_client_id, ""]
# io.puts(@@chat)
end
end
server = BasicServer.new(1234)
server.start
#sleep 120
#server.shutdown
Hope you could give me some insights on what could be going wrong from
my end.
Thanks a lot for your time!!