Author Topic: Web-Based Chat  (Read 4662 times)

0 Members and 1 Guest are viewing this topic.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Web-Based Chat
« on: April 18, 2008, 05:39:50 pm »
Hey, I'm working on some new projects for web based programming, and I was curious to hear input about the best way for web-based chat, using Ajax.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Web-Based Chat
« Reply #1 on: April 18, 2008, 07:30:35 pm »
Well, IMO the most straightforward way to do it is to maintain each "conversation" as a single row in a conversations table and then all chat messages indexed by the PK of the conversation it's taking place in.

Your ajax call would probably poll the server for updates.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: Web-Based Chat
« Reply #2 on: April 18, 2008, 07:43:50 pm »
what kind of chat are we talking about? instant messaging, or like irc? in either situation, i don't think i'd store any chat in a database. i've never created a web based chat room, but i think there are ways to get that real-time feeling without hitting the database for new chat data. some things that just come to mind are ajax, and flash working together - a lot of things use this now days.
http://www.chyea.org/ - web based markup debugger

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: Web-Based Chat
« Reply #3 on: April 18, 2008, 07:47:00 pm »
Yeah, like an instant message kind of thing, at least without, a noticeable refresh if one requires it....

I was actually just reading about that...(using ajax and flash together).. I just wanted to know you guys' opinions..

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: Web-Based Chat
« Reply #4 on: April 18, 2008, 08:53:44 pm »
well, i'm not quite sure how they interact, but i think what happens is that flash is capable of keeping open sockets, which removes the need for the database. so, flash handles the data, and can either modify the page, or requires javascript to modify the page. the instant messaging thing should be relatively easier than the irc-like chat, i would think. there's plenty of free ones out there for you to kind of check out. also, channels on freenode are always a great resource - #flash, or #ajax

heck, you could even debug the AIM web based chat client.
http://www.chyea.org/ - web based markup debugger

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Web-Based Chat
« Reply #5 on: April 18, 2008, 09:48:16 pm »
No, I don't believe Flash is capable of keeping open sockets.  Flex might be though, but ActionScript is not.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Web-Based Chat
« Reply #6 on: April 19, 2008, 12:13:04 am »
One way (that Skywing used on his BinaryChat interface, among other people/projects) is to keep an open socket (using a custom Web server, an ISAPI program, etc) to the client that doesn't send a content-length. The browser will keep listening for data, and you can send it whenever it arrives, giving the appearance of a dynamic application.

May not be the best way, but it's among the most functional.

Offline warz

  • Hero Member
  • *****
  • Posts: 1134
    • View Profile
    • chyea.org
Re: Web-Based Chat
« Reply #7 on: April 19, 2008, 05:06:20 am »
No, I don't believe Flash is capable of keeping open sockets.  Flex might be though, but ActionScript is not.

I'm not sure you know what you're talking about - go read up on it, some. Yes, Flash can keep open sockets via xmlsockets - check out www.gotoandplay.it. Also, Flex is a framework built upon flash - so saying Flash can't do it, but Flex can makes no sense.

edit: i just have to mention that i've never done it, but know this is how it's done.
« Last Edit: April 19, 2008, 11:41:38 am by warz »
http://www.chyea.org/ - web based markup debugger

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Web-Based Chat
« Reply #8 on: April 20, 2008, 11:18:45 pm »
Might want to read meebo's blog. There was one (fairly recent) post in particular I'm thinking of that explained exactly how they avoid polling the server.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Web-Based Chat
« Reply #9 on: April 21, 2008, 01:28:37 am »
According to this post, they use AJAX.  AJAX still polls the server in the background; it just has a long timeout on the XMLHttpRequest object (30 seconds).  See the screenie.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Web-Based Chat
« Reply #10 on: April 28, 2008, 02:33:18 pm »
Technically, they do poll. What I meant was that they use a strategy that makes it seem as if they are not polling.

Quote
The second technique is generally referred to as long-polling. It works much like polling, except that instead of the server returning immediately, the server keeps the connection open until it has a new update. This means that an IM message can be pushed to the meebo window as soon as it is available. Alex Russell recently coined the long-polling method “Comet” (Ajax & Comet? – you can tell Alex has a good sense of humor).

I found the blog post: http://blog.meebo.com/?p=126

http://www.google.com/search?q=site%3Ablog.meebo.com+XMLHttpRequest

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!