Jump to content


Photo

live chat/chatrooms


  • Please log in to reply
6 replies to this topic

#1 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 26 October 2006 - 06:24 PM

in a person to person chat room if you're using php you would need to keep reloading the page right? to make it so you dont have to load it can you use javascript? if so how would i do that.. and how exactly does the person to person chat work.. i have an idea.. well its actually pretty confusing.. would i need to be using asp, whatever that is?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 26 October 2006 - 06:32 PM

ASP is simply another server side scripting language (Microsoft's, actually) like ASP. In theory, a PHP chatroom would have to reload the page every few seconds to show you the new posts. However, if you use AJAX (client side HTTP requests), you could pull the newest posts every few seconds and simply tack it on to the tail of the chat content. That would be your best bet if you're wanting to use PHP for one.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 26 October 2006 - 06:54 PM

when someone sends a message when they click send will it have to go to a script to get transfered over? and then redirected back to the page? how would that work?

#4 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 26 October 2006 - 07:35 PM

anyone?

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 26 October 2006 - 07:56 PM

when someone sends a message when they click send will it have to go to a script to get transfered over? and then redirected back to the page? how would that work?


Basically, you want a table that will hold the conversation. When someone hits "send", you'll want to send their entry to append to the end of the record. Of course, since they're the one sending the message, you can immediately display it on their screen with javascript. Then, you also want to have an HTTP request running to the server to grab any posts since the last request (usually somewhere around the ballpark of 8-12 seconds is a good gauge). If there are new entries, retrieve them via the HTTP request and update the display accordingly. Otherwise, it's the exact same logic behind every chatroom you've ever visited.

Hope this helps.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 26 October 2006 - 08:01 PM

thanks.. how can i use a HTTP request to catch the posts? its like this right? a chater sends a message and it appears on their screen on the bottom of the record and then the other chater must catch that post with the HTTP request and then display it onto their record that way? would i need to send the message through a script so i could get it into a variable?

#7 R_P

R_P
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts

Posted 26 October 2006 - 08:38 PM

jwk, you're going to need at least a basic knowledge and understanding of JavaScript and the XMLHttpRequest element to make an AJAX chat. I am working on a flat-file based Ajax chat here (second link from the bottom on that page).

What I did was initiate the request element every time the form was submitted or enter key pressed. The request sent the line of chat to a PHP script which writes it too a flat file, while a different request element checks the flat file for changes. If a change happened, a line difference calculation occurs and PHP returns all lines submitted since the last change.

If you want to circumvent the AJAX process, just split a page into two frames. In one frame, make a page that auto or meta-refreshes at a set interval, and in the other frame, create a basic form that posts information to a database whose action property is itself. Thats about as basic as PHP applications get.
Pro in: Win2K3S | Apache2 | PHP5 | Perl5 | MySQL | MSSQL | Firefox | Photoshop
Student of: Ubuntu6 | Java | C | VB.NET | ASP.NET
Developer: Roddzilla Webstudios, Burrson CG, DVIDSHUB, The Four Nations
Student: Georgia Tech, Georgia Tech College of Computing




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users