1

Which programming language should I use to write an Instant Messenger? Here are the goals:

  • should be able to handle many, many users (at least for proof of concept)
  • protocol should be based on json or maybe binary data. i guess json is easier to implement and extend. I don't want to use XML because of the overhead. I know it's not much data but it should be as fast as possible especially on slow networks (e.g. mobile).
  • users should be able to be logged in on multiple devices simultaneously
  • history should be saved server sided so it can be viewed on all devices
  • server should keep a lot of idle clients alive
  • file transfer (not quite sure on how to realize, maybe a different network socket so it does not block chat messages on client side)
  • MySQL auth

(No, XMPP is not an option).

I'm a web developer with good experience in PHP but that is not an option for this project. I also have experience with Javascript (mainly for websites), but it would be easy for me to work with node.js and I have little experience with C#.Net and could also write C#.Mono. The server I want to write should run on Linux. I have no experience with Java but if it's the best way I could learn it.

I've read much about node.js and that it's evented I/O is really good for network applications and web servers. But what about instant messengers? The main part is to save messages and proxy them to the other room participants, so it's "network".

I also thought about C# which offers asynchronous sockets which work with a thread pool afaik instead of a event queue.

I'm not sure which of them is most efficient in regard of an IM server.

It would be nice if someone could give me a hint. I know C++ would probably be the best way but I somehow don't really like that language and it's hard to learn.

Spammer
  • 31
  • 1

2 Answers2

5

You can do all this in any normal programming language (C#, Java, C++, etc...), as long as you're competent enough in that language.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Any of those solutions will do. You can write evented networking code in pretty much any language - and yes, it's pretty cool to use it in scenarios like this one.

If you want something that will give you some kind of framework for easier networking, I'd recommend trying Erlang, but it might be tough to learn for a single project. node.js might be tricky with regards to keepalives / resource management on dead connections and similar scenarios where you don't really get an event.

If you're already familiar with c#, using mono might be the safest / fastest thing for you. Apart from that - you can write anything in any language - just use what you're comfortable with (unless you actually want to learn something new).

I don't know why you wrote that jabber isn't an option, but if it's only the xmpp technology you don't want, why not use a typical SIP proxy/server? (for example OpenSIPS) It's got MESSAGE request handling, subscriptions, authorization (with db) and keepalives already available. You can scale / cluster / shard OpenSIPS in pretty much any way you want.

viraptor
  • 33,322
  • 10
  • 107
  • 191
  • I'm not really experienced with networking... Are asynchronous sockets better than synchronous sockets on such a project? Chat messages are usually quite small and it would only block for several milliseconds. – Spammer May 31 '11 at 12:43
  • Sending a tcp message can block for arbitrary amount of time. You can solve that with either threading or async sockets. If you really want to scale for lots of users, you never want to block - just queue and send once you know it's possible. Probably even a pool of threads with async dispatchers is the way to go since you'll have to interleave keepalives, normal messages and file transfers. – viraptor May 31 '11 at 12:49
  • That's kinda part of my initial question. With node.js the JS engine does that stuff for me, so I can handle chat messages as events. On C# I have the opportunity to use thread pools (i think BeginX on C# already uses a thread pool. Otherwise it would spawn and kill a huge amount of threads) – Spammer May 31 '11 at 12:55
  • Unless I missed something, handling idle connections is not easily possible in node.js. You can defer sending, but that doesn't tell you much about the current state and keepalives can start queueing on their own. You're left with dead state / socket you have to cleanup (just google for node.js resource management on dead connections to see how many not-obvious situations can arise) – viraptor May 31 '11 at 13:16
  • Handling idle connections in node.js is no problem, even if you want to ensure that connections do not time out: send a ping to every client every X secs, all timed out clients will be detected as gone away. – Tobias P. May 31 '11 at 13:49