1

I have to develop a multiple users chat application (like msn). I don't what to use any framework to build it because I want to learn how those things work.

I am developing it in Delphi or C# but it does not really matter. What matter is that the chat client is going to be an app, not a browser.

The question is: what is the best way of handling messages between the clients?

So far, I know those techniques:

Pushlet

Polling

Long polling

Link to the Wikipedia

Community
  • 1
  • 1
Rafael Colucci
  • 6,018
  • 4
  • 52
  • 121

2 Answers2

3

It looks like all of these are particulary useful for HTTP, since HTTP doesn't really allow connections to be permanently open. This is the way to go if you're writing a web based chat client that use Ajax (or REST calls anyway).

If you're writing a chat application (either P2P or client/server) yourself, you can create a connection that stays open permanently.

So, the server just listens on a given port. The client tries to connect to that port on the server's IP address. If the connection succeeds, it stays open until the client user closes the program (if all goes well).

Delphi does have a chat application demo that uses the Indy TCP components. You can take a sneak peak there, even if you're going to build it yourself afterwards.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Thanks for pointing me to indys demo, but it is too simple. But i think I know how to deal with sockets. – Rafael Colucci Dec 15 '11 at 20:16
  • 1
    @Rafael HTTP 1.1 still does not introduce server-initiated messages - it is always request/response. The WebSockets extension of the HTTP protocol in HTML5 introduces server-initiated messages. – mjn Dec 15 '11 at 20:18
2

Do you need to support (tens of) thousands of simultanous connections? If yes, I recommend to take a look at

which are used in application servers and standards like Servlet 3.0 to minimize the number of worker threads and speed up network operation

There is a IOCP library for Delphi - see Is there a I/O completion port based component for Delphi?

Also HTTP could be used as the internal protocol, the new Microsoft http.sys library provides a great foundation and is included with new versions of Windows.

To give an impression how efficient messaging servers can be: on relatively modest hardware, the open source ActiveMQ Apollo server can handle 1.2 million messages per second. (It is written in Java)

Community
  • 1
  • 1
mjn
  • 36,362
  • 28
  • 176
  • 378
  • I dont need to support (tens of) thousands of simultanous connections. In that case, should I stay with Pushlet? – Rafael Colucci Dec 15 '11 at 20:46
  • @Rafael then you could just use Indy :) Pushlet = long polling HTTP + JavaScript. Something like Telnet or a simple messaging protocol like STOMP or MQTT would be easier to implement. – mjn Dec 15 '11 at 20:54
  • Well, neither my client nor my server are web based. Them i think i should use Pushlet = Indy TCP client + Indy TCP Server + STOMP. It should be ok, right? – Rafael Colucci Dec 15 '11 at 20:59
  • @Rafael HTTP is a popular protocol for non-Web clients too, for example most SOAP and REST services use it. It has the advantage that most corporate firewalls allow HTTP. So your server does not require any special configuration on the user end. HTTP does not mean to use HTML. – mjn Dec 16 '11 at 06:32