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.
You can do all this in any normal programming language (C#, Java, C++, etc...), as long as you're competent enough in that language.
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.
Related
I want to start writing games/applications with client-server architecture. I explored the internet and everyone tells that the best way is to use c# built-in socket libs. But If I am forced to write everything on my own (singletons, threads, keeping connection alive, parsing in-out messages etc.) I bet I will do it for months. Do you know any library supporting client-server based connections for C# (Forms/WPF/maybe Mono)? I can not find any "quite new" threads/information about this.
i think your problem will be, that you will not find an predefined lib which fits your requirements.
But if you write it with Visual Studio autocomplete will help you a lot.
However there are lots of question for me. What exactly is your target? What kind of game do you thinking of?
These factors affect your complexity of your "socket" enormous.
I think for a small "Ping Pong"-Multiplayer-Game your Socket is quite easy to do.
This is hard for me to explain and even harder for me to visualize how I'd do it, since I don't know the bounds of communication with websites with Java and C#, so if I banter a lot/make no sense in the process of describing this, I apologize.
Basically, I'm making a 'bot' for www.plug.dj. This bot is able to do things on command like kick users, ban users, send chat messages, delete chat messages, say random things, etc. As of right now, it's powered by a simple one-file JavaScript code with a ton of listeners and callbacks using the Plug.dj API to handle them. This is ALL engineered by JS -- on the back-end, I think Plug.dj is powered by Python, I could be wrong.
Anyway, what I would LIKE to do is create this bot on a language other than JS. It's really basic and not super powerful, and there are things like communicate with databases and such that I'd like to implement that aren't possible/convenient with JS. I just want to know if this is possible, and if so, where should I start looking?
I'd prefer a language like Java or C#. If there's any more info you need to know in order to answer this, let me know, please! I'd like to start working on this, I think it'd be fun to learn how to communicate with websites with Java/C#/whatever.
If the bot javascript runs on "their" server, then there is no simple solution. They are providing a mechanism for running "your" javascript on their server, but the chances are that they don't support other languages. (And the only way to find out would be to ask "them"). Assuming that the answer is "no", you would need to investigate whether you can implement your "bot"s functionality in client-side code; e.g. a custom client that you implemented from scratch in Java or C# or whatever. That's a big "if" ... because it will only work if they expose the server functionality you need in their external APIs.
OTOH, if the bot javascript runs on "your" server, then you should be able to change it to support other languages. (It wouldn't necessarily be easy though ...)
My advice would be to take a deep breath ... and stick with Javascript. We all have to use languages that we don't think are "fun".
I honestly would just leave it in javascript if it is something you need to have run in the client.
If you need to make database calls, you can introduce a web services layer in between against which you can make AJAX calls which interact with databases.
I think your perception of javascript as basic and not very powerful is not a very good one. They are very complex apps build today in just javascript and HTML5. You just might need to start looking at things like backbone.js, underscore.js, and similar libraries that can help provide more advanced code organization functionality available to you.
If however you are looking at building something that individual clients are not going to have installed in their browsers, but rather would just interact with the website in an automated admin, then certainly you can establish you own web service in whatever language you like to interact with their API's and perform admin tasks.
If they provide a JavaScript library that runs client side, it seems likely that it will be communicating with the server over HTTP. Therefore, it should be possible for you to analyse the library and the calls it makes to reverse engineer the server API (which would be the HTTP calls) and re-implement it in the language of your choice.
Looking at the code of bot.js:
https://github.com/backus/Plug.DJ-Javascript-Chatbot/blob/master/bin/bot.js
it seems everything comes down to calls against their API object, eg API.getDJs(), API.getWaitList() etc. If you can determine how this API object works, then you might be able to reverse engineer and re-implement.
I want to study network programming, there’s a chapter named “networking” in “C# in a nutshell”, this chapter contains ‘WebClient’, ‘HttpClient’, ‘FTP’, ‘TCP’ and so on. But some body tell me to study WCF, I want to know what’s the relationship between WCF and c# networking programming, I remembered I have seen somewhere that WCF encapsulates network programming, it’s more flexible and convenient, but not efficiency. Does this mean the relationship between them like ado.net technology with orm? Which I should to study, network programming or WCF? Does c# network programming an obsolete technology?
Thanks
"network programming" usually refers to sockets, this is the lowest level of network communication and deals with pushing bytes on the network - all the other communication systems are built on top of sockets.
Most projects don't use sockets directly because there are simple higher level systems you can use but I think it's still worthwhile to learn the basics because it's not so complicated and it will help you deal with problems in those higher level systems.
The next level is WebClient and friends, those are relatively straightforward classes that implement a communication protocol on top of sockets (for example HTTP).
It's definitely worth your time to learn how to use those because they are simple and extremely useful (for example if you want to pull a file from the internet or communicate with a 3rd party service).
At the highest level you have WCF, this is an extensive (and in my personal opinion over-complicated and over-engineered) framework that gives you a class interface for an external network based service while trying (unsuccessfully) to hide all the communication details.
WCF is very popular in big organizations and "enterprise systems", so, if you want to get a job developing enterprise systems for big organizations learning WCF is a very smart career move.
So, my advice, start with sockets, learn just the basics - this will help you understand how things work under the covers (this will become very useful when you have to debug network problems).
Than move on to the higher level classes, write a simple program that uses WebClient to read a page from the internet so you are comfortable with the concept, don't bother
with all the advanced options, they are there and you can look them up later when you need them.
Learning just the basics of sockets and WebClient should take just a few hours, after that (if you want to work on big systems) learn how to use WCF.
Then you will have the WCF knowledge for your resume and you will know how to just get something over the internet with a few lines of code without using a gigantic framework when you don't need it.
If you want to study network programming you'll want to read about sockets and TCP/IP (and later on UDP if you want to stream or smaller packets). Sockets are the API that most OS:es uses to handle protocols like TCP/IP.
Your comparison is correct. WCF is a framework on top of the networking layer in .NET. Just as ORMs are frameworks on top of ADO.NET.
WCF is not the so called network programming. They are two concepts with some relationship.
Usually network programming means socket programming and TCP/IP. You are supposed to be familiar with protocols, such as HTTP, FTP, SNMP and so on. Then you can write programs that serve as protocol servers and clients. Network programming is still hot, though it is no longer that popular.
WCF is a framework for web services, which is HTTP only (mainly SOAP).
If possible, you should learn both or at least know of both.
How to create a NATIVE chat app for the iPhone? So far we have been exploring a few options:
Creating a web service using php or other web based language and have the app connect to that. Only problem is we can't figure out how to create "push" messaging with this, where the user will not have to refresh the conversation constantly.
Hosting an application on a server such as Windows Azure which will communicate to the iPhone app using TCP/IP. This way it seems like "push" messaging could be achieved by simply sending a packet to the iPhone. However, we have never done this before and don't know if we would run into any unforeseen potholes.
Have any of you made such an app before? If so how did you go about doing it? If not, what method would you recommend?
Thank you in advance!
EDIT:
To tell you exactly what we're trying to do: we need to make an app where a user can join a chat room and send/ receive messages from that chat room. There will also be custom features like that users will have their own profiles, etc. We would also like to make this as flexible as possible, so that we can integrate it on other platforms like android and blackberry later on.
So essentially the part that I'm stuck on is the send/ receive messages from a chat room. What technology should we use server side?
Something with an open socket, like Socket.IO could work. Node.js is a good server-side framework to explore. Here's an related SO question: iPhone Objective-C socket communication with Socket.IO
EDIT:
Question has changed since posting this answer -- originally question asked about web apps. ALso, originally the question was not clear that you wanted answers about the server side more than the client side.
On the server side, I would still recommend Node.js -- sounds like you want to use C# though, which makes me wonder why you're asking again about what server side tech to use. Most languages will provide you with ways to connect a socket to a client and access a database, which are the two main requirements of the app that it sounds like you want to make. Use whatever language you're comfortable with. However, some are going to come with libraries that may come in handy for this type of communication -- Node.js and Ruby on Rails (more useful if you want to do a polling-based solution)
Look at http://code.google.com/p/cocoaasyncsocket/ for a good library for doing socket communication from the iPhone without having to delve too deep into the low-level functions.
I've done this several times. Scaling to 100K concurrent users is non-trivial. If you want an off-the-shelf system I suspect ejabberd may do what you want. although the protocol IMHO is too verbose and uses far more bandwidth than necessary.
If you want to write your own solution and have the flexibility to write your own protocol and have the maximum possible scalability in the future then use a language that allows you to distribute the application across several servers. It is easier to allow that from the get go rather than writing a single server solution then have to retroactively make it distributable.
Having written servers like this in c++, Java and Erlang I would say the easiest and most relevant tool was Erlang. It makes good use of multi core processors and with a good design it facilitates distributing across several servers. C++ was the hardest!
I have also used Java with tools like JETTY and RabbitMQ to write a highly scalable system that required using HTTP as the protocol.
Personally I prefer a custom binary protocol as it allows you to reduce bandwidth to a minimum, and avoids DOS attacks and such as the protocol is well defined and lengths are sent before the packet, where as non binary protocols need to be parsed as they come in, with no idea of how big the packets may be.
Why not try XMPP protocol first? XMPP is based on TCP/IP.
There are several OpenSource server solution, clients, and application libraries. XMPP already supports chat room like service. You can define extension easily.
I have a quite advanced application, where I need to add some client/server functionality. Some examples of functionalities is:
Chat
One vs. one fight in a browser game
Draw people on a map
I am creating this application in ASP.NET and AJAX. I do not use Silverlight/Java Applet/Flash or anything else. If possible, I do not want to change this for other reasons.
I thought about creating some kind of game server, and then communicating either web services or TCP protocol: But I have NO idea if this is a good idea. Also, I don't know how to do this.
So my question is:
What's the best way to implement this? And is it even possible? And if it is, could you give a reference or two?
Thanks a lot,
Lars
For doing chat & multiplayer games, the crux of the problem is in getting the server to asynchronously send messages to the client. This can be accomplished by a method called reverse-Ajax (or commet). Here is a simple example for how to do reverse-Ajax with ASP.NET. This is a very involved concept (at least until we can use HTML5 WebSockets) with a lot of thought going into security concerns, et al. I assume that by asking this question you are already quite familiar with Ajax & browser scripting (if not, you have a lot of reading to do).
Tutorial on writing a basic chat server: (in c# no less)
http://www.dreamincode.net/forums/topic/33396-basic-clientserver-chat-application-in-c%23/
Sgive you a good foundation on server development.