Well, I know there are so many IM services. and that I want to build an IM system is just for practicing my programming skill.
Here there are several questions that come up to my head when starting to design it. As far as I know, we can only receive a response from the server by sending a request to it, but, for an Instant Message System, this is not realistic, by doing that, the Instant Message System is not instant. Let's assume that there is a server and several clients sending messages to it and receiving messages from it, how can I achieve that a client is able to receive a message from the server without sending a request on it's own initiative? this seems not realistic either.
Or I can set a timer using Javascript for a function to be executed from time to time to send asynchronous requests to the server and check if there are any new messages? but this seems not so efficient...

Any ideas?

Recommended Answers

All 5 Replies

Indeed, given that the underlying protocol used in almost all the cases, viz. TCP is connection oriented i.e. following the request/response model, you have to resort to some sort of callbacks or regular polling. Frankly speaking, asynchronous I/O, push pull technology etc. are pretty advanced concepts, not to be messed if you are just starting out. But anyways, to get started read this article which provides a sneak peek into Asynchronous messaging.

For creating standalone IM clients [not web based], look into the different protocols specifically aimed at IM, especially XMPP.

If you want to see example of working chat system get copy of Java How to Program, 6th edition from Deitel and check out chap 24 at the end

I'm a bit perplexed... since this topic is in the Java forum I'm assuming that some Java programming is involved. As such, I'm imagining a Java Applet since we're speaking about something that's web based. Please correct me if I'm wrong, but if the server knows both users that belong to a conversation, then when one user sends a message (which would be a message to the server), then surely the server could just relay this message across using Sockets in Java. Both the server and the clients need to be listening for communication and everything else is abstracted from us isn't it?

I see that ~s.o.s~ pointed you to an AJAX article... hmmm well I suppose that is Java, but a limited subset. Isn't this more of a web development topic?

> I see that ~s.o.s~ pointed you to an AJAX article.

It was because he mentioned Javascript hence a reference to the Ajax article was in order.

Or I can set a timer using Javascript for a function to be executed from time to time to send asynchronous requests to the server and check if there are any new messages? but this seems not so efficient...

Oh I didn't mean that your post wasn't called for ~s.o.s~, I certainly respect a featured poster such as yourself. I actually skimmed the original post and didn't notice he mentioned JavaScript hehe. It was your reply that made me realize that it was JavaScript related.

I was just confused about why the post was here.

commented: Heh, no problemo. :-) +26
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.