Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Q: writing a web chat room--sharing info?

Reply
Thread Tools

Q: writing a web chat room--sharing info?

 
 
Matt C
Guest
Posts: n/a
 
      06-22-2005
New to Ruby, and haven't tried anything like this before.

I'd like to write a web page that acts like a "chat room". (Actually,
I'd like to write a game that incorporates the chat room idea, but first
things first.) Nothing unusual here: a big window that shows what other
people have typed, and a small textbox below where you can type your own
messages. This can be done with ajax, there are some examples on the web
(but not Ruby ones, that I found anyway).

I'm not sure what the best way to share info between the different web
users is. There are several possibilities I can think of: use a text
file, use a database, write a daemon, use memcache.

I'm leaning toward using a database at this point because 1) there won't
be issues finding hosting if I use a db, and 2) I have experience with
databases, unlike daemons and memcache. Still, it seems like overkill to
go in and out of a database when all I really want is shared access to an
array.

Does anybody have a better idea, or other suggestions?

Also, a completely unrelated question for those who read this far. I
notice there seem to be two competing Ruby conventions for naming
methods. My copy of the Pickaxe book (first edition) uses
mixedCaseNaming. Other sources (Ruby itself, frex) use
underscore_naming. Is one of these prevalent, or is it whichever you
like better?

Thanks for any advice,

Matt
 
Reply With Quote
 
 
 
 
Jeffrey Moss
Guest
Posts: n/a
 
      06-22-2005
I was thinking about how to do a chat room like this. The conclusion I
reached was that if I had the page "refreshing" every second to display new
messages, it would create a high load on the server, each of my rails
requests typically takes an entire second to process, so my solution was to
write the chat conversation to an html file in a folder in the web root
where mod_rewrite was disabled and that way the web server could serve the
file with haste and free the web server from unnecessary processing.

-Jeff

----- Original Message -----
From: "Matt C" <>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby->
Sent: Wednesday, June 22, 2005 11:40 AM
Subject: Q: writing a web chat room--sharing info?


> New to Ruby, and haven't tried anything like this before.
>
> I'd like to write a web page that acts like a "chat room". (Actually,
> I'd like to write a game that incorporates the chat room idea, but first
> things first.) Nothing unusual here: a big window that shows what other
> people have typed, and a small textbox below where you can type your own
> messages. This can be done with ajax, there are some examples on the web
> (but not Ruby ones, that I found anyway).
>
> I'm not sure what the best way to share info between the different web
> users is. There are several possibilities I can think of: use a text
> file, use a database, write a daemon, use memcache.
>
> I'm leaning toward using a database at this point because 1) there won't
> be issues finding hosting if I use a db, and 2) I have experience with
> databases, unlike daemons and memcache. Still, it seems like overkill to
> go in and out of a database when all I really want is shared access to an
> array.
>
> Does anybody have a better idea, or other suggestions?
>
> Also, a completely unrelated question for those who read this far. I
> notice there seem to be two competing Ruby conventions for naming
> methods. My copy of the Pickaxe book (first edition) uses
> mixedCaseNaming. Other sources (Ruby itself, frex) use
> underscore_naming. Is one of these prevalent, or is it whichever you
> like better?
>
> Thanks for any advice,
>
> Matt
>




 
Reply With Quote
 
 
 
 
Ian Hobson
Guest
Posts: n/a
 
      06-22-2005
In message <Xns967D82805B0FBcanimal@68.12.19.6>, Matt C
<> writes
>New to Ruby, and haven't tried anything like this before.
>
>I'd like to write a web page that acts like a "chat room". (Actually,
>I'd like to write a game that incorporates the chat room idea, but first
>things first.) Nothing unusual here: a big window that shows what other
>people have typed, and a small textbox below where you can type your own
>messages. This can be done with ajax, there are some examples on the web
>(but not Ruby ones, that I found anyway).
>
>I'm not sure what the best way to share info between the different web
>users is. There are several possibilities I can think of: use a text
>file, use a database, write a daemon, use memcache.
>
>I'm leaning toward using a database at this point because 1) there won't
>be issues finding hosting if I use a db, and 2) I have experience with
>databases, unlike daemons and memcache. Still, it seems like overkill to
>go in and out of a database when all I really want is shared access to an
>array.
>
>Does anybody have a better idea, or other suggestions?
>

When I wrote one, this is what I did - using a database.

I set up two conversations, using a foreground and background window.

The foreground window loaded, opened the background window, and
presented a simple form to the user. On clicking send, the content was
POSTed using javascript. The server added the line to the conversation,
and returned a null reply (so the window remained without the users
input!).

The background window asked for the conversation from message X, using
GET.

When this came back it was added to the foreground panel using
javascript. And the background window asked for the next (from X+1). It
could receive multiple lines.

The server handling the requests would sleep for (iirc) 2 seconds, and
look, sleep 2 and look, before finally giving a "there are 0 lines to
add" reply every 10 seconds or so. If it found lines to add these were
returned as soon as seen.

Result was user updates within at most 2 seconds, plus transit times -
it felt responsive.

Resulting server load was remarkably light. A conversation with 50
scripts all chatting 1 line per second, hardly made any impression on
the CPU usage on my 500MHZ firewall acting as server. It filled log
files though.

If I did it again, I would use an ipanel and httprequest, but the same
method, thus avoiding pop-up blockers which sometimes caused me a
problem.

You cannot keep the thread running in the server, indefinitely for two
reasons: first your hosting company will kill it after a few minutes as
a runaway, and second, the user's browser will give up waiting if there
is no response.

Hope this give you some ideas.

Regards

Ian

--
Ian - posting to a Newsgroup. Please remove everything to reply.


 
Reply With Quote
 
Timothy Hunter
Guest
Posts: n/a
 
      06-22-2005
Matt C wrote:
>
> Also, a completely unrelated question for those who read this far. I
> notice there seem to be two competing Ruby conventions for naming
> methods. My copy of the Pickaxe book (first edition) uses
> mixedCaseNaming. Other sources (Ruby itself, frex) use
> underscore_naming. Is one of these prevalent, or is it whichever you
> like better?

The 2nd edition uses underscore_naming (a.k.a. "what God intended"
throughout.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chat Server and Chat Client for INTRANET diptanu@gmail.com Java 0 01-30-2006 06:56 PM
IAS Customer Web chat - September 29, 2005 (1:00 - 2:00 P.M. Pacific time) kapil [MSFT] Wireless Networking 0 09-28-2005 06:04 PM
IAS Customer Web chat - September 29, 2005 kapil [MSFT] Wireless Networking 0 09-14-2005 06:37 PM
IAS customer web chat March 29 kapil [MSFT] Wireless Networking 0 03-28-2005 07:50 PM
web chat development, http header connection: keep-alive Luiz Alberto Gibson da Costa ASP .Net 0 08-06-2003 01:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57