Creating a live chat O_O

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Creating a live chat O_O

Post by Mythic Fr0st »

I want to add a live chat box to my game...

I need to know what languages to use, and basically, HOW to do it lol
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You can do it with JS and PHP in the form of AJAX (you can download these things via hotscripts or google for them too). Java also works nicely for peer-to-peer type applications like this :)
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

Java has built in connectivity functions ideal for this sort of thing
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

If you're not hip to the ajax jive, the old school way of doing it would be to stick your chat box into an iframe and meta-refreshing every second or so. The iframe's source would of course be a php script that pulls the messages from the database in order.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

evilchris2003 wrote:Java has built in connectivity functions ideal for this sort of thing
Well, PHP can do it if you relay *everything* via the server.

With Java however you can just "track" the client IP addresses with the server and the have applets connect directly to the remote peer. The AJAX approach in PHP has been proven to work well though and will work with more browsers since Java is often disabled on the client.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

hmm

Post by Mythic Fr0st »

Well, What is going to be the most stable & effective?

(I would guess java, but can you use java with php & html?)
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I think they are referring to JavaScript when they say Java. JavaScript will be interpreted on the client side, and will interact with PHP/MySQL by way of the XMLHttpRequest object. While using Javascript is probably the most seamless, my suggestion would be compatible with any client (as it doesn't depend on JS, and JS can be disabled by the client). If your game is already using JS, you may as well go with AJAX.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

actually I'm pretty sure d11 was actually talking about java.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

The Ninja Space Goat wrote:actually I'm pretty sure d11 was actually talking about java.
Ah, so he was (just reread his first post). Seems though that it would be simpler to make asynchronous calls to a php script from javascript every so many seconds as opposed to writing an applet.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ah

Post by Mythic Fr0st »

I'll check out ajax, although it sounds like a cleaning product:P

I already have a little JS & css, but mostly html & php

Im glad its JS and not java, cus the program I downloaded for it, wont start lolz

Thanks alot guys

now I just gotta figure out how to do it lolz, starting with making the box for the chat o_O

Q1: how do I make the box for the chat, like a black box, where you can type over... if you look at a game like
http://www.shimlar.com and many others, they have sort of a text area, thats my first goal o_O
Post Reply