(轻量级)即时通讯:C#.Mono、node.js 还是其他?
我应该使用哪种编程语言来编写即时通讯程序? 目标如下:
- 应该能够处理很多很多用户(至少为了概念证明)
- 协议应该基于 json 或二进制数据。我猜 json 更容易实现和扩展。由于开销,我不想使用 XML。我知道数据不多,但应该尽可能快,尤其是在慢速网络(例如移动网络)上。
- 用户应该能够同时在多个设备上登录
- 历史记录应该保存在服务器端,以便可以在所有设备上查看
- 服务器应该保持大量空闲客户端
- 活动文件传输(不太确定如何实现,也许是不同的网络) (不
- MySQL 身份验证
,XMPP 不是一个选项)。
我是一名 Web 开发人员,在 PHP 方面拥有丰富的经验,但这不是这个项目的选择。我也有 Javascript 的经验(主要是网站),但使用 Node.js 对我来说会很容易,而且我对 C#.Net 的经验很少,也可以编写 C#.Mono。我要编写的服务器应该在Linux上运行。我没有 Java 经验,但如果这是我学习它的最好方法。
我读过很多关于 Node.js 的内容,并且它的事件 I/O 对于网络应用程序和 Web 服务器来说确实很有好处。但是即时通讯工具呢?主要部分是保存消息并将其代理给其他房间参与者,因此它是“网络”。
我还考虑过 C#,它提供异步套接字,该套接字与线程池(afaik)而不是事件队列一起使用。
我不确定其中哪一个对于 IM 服务器来说最有效。
如果有人能给我提示,那就太好了。我知道 C++ 可能是最好的方法,但我不太喜欢这种语言,而且它很难学。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用任何普通编程语言(C#、Java、C++ 等)来完成所有这些工作,只要您对该语言有足够的能力。
You can do all this in any normal programming language (C#, Java, C++, etc...), as long as you're competent enough in that language.
这些解决方案中的任何一个都可以。您几乎可以用任何语言编写事件网络代码 - 是的,在像这样的场景中使用它非常酷。
如果你想要一些能够为你提供某种框架以方便联网的东西,我建议尝试 Erlang,但对于单个项目来说可能很难学习。 Node.js 在死连接和类似场景(您没有真正收到事件)的保持活动/资源管理方面可能会很棘手。
如果您已经熟悉 c#,那么使用 mono 对您来说可能是最安全/最快的方法。除此之外 - 您可以用任何语言编写任何内容 - 只需使用您熟悉的内容即可(除非您实际上想学习新的东西)。
我不知道你为什么写 jabber 不是一个选项,但如果你只是不想要 xmpp 技术,为什么不使用典型的 SIP 代理/服务器呢? (例如 OpenSIPS)它具有 MESSAGE 请求处理、订阅、授权(使用数据库)和 keepalives 已经可用。您几乎可以以任何您想要的方式扩展/集群/分片 OpenSIPS。
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.