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

Discussion in 'Ruby' started by Matt C, Jun 22, 2005.

  1. Matt C

    Matt C Guest

    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
    Matt C, Jun 22, 2005
    #1
    1. Advertising

  2. Matt C

    Jeffrey Moss Guest

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

    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" <>
    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
    >
    Jeffrey Moss, Jun 22, 2005
    #2
    1. Advertising

  3. Matt C

    Ian Hobson Guest

    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.
    Ian Hobson, Jun 22, 2005
    #3
  4. 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.
    Timothy Hunter, Jun 22, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ady

    Chat room type textarea

    Ady, Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    470
  2. Jemdam.com
    Replies:
    8
    Views:
    595
    JennyLin
    Sep 3, 2005
  3. =?Utf-8?B?SklNLkgu?=

    q; chat room application

    =?Utf-8?B?SklNLkgu?=, Aug 7, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    441
    Mike Lowery
    Aug 7, 2006
  4. mercuryguy

    oop design for a chat room

    mercuryguy, Oct 2, 2005, in forum: C++
    Replies:
    2
    Views:
    319
    Shezan Baig
    Oct 2, 2005
  5. Ruso
    Replies:
    1
    Views:
    109
    Randy Webb
    Nov 13, 2006
Loading...

Share This Page