简体   繁体   English

Java(或PHP)中的Websockets服务器

[英]Websockets Server in Java (or PHP)

I could need your experience according server implementations for the currently evolving Websockets in HTML5. 对于HTML5中当前不断发展的Websockets,我可能需要根据服务器实现的经验。 We want to use this technology for a project using common webbrowsers on the client site. 我们希望将此技术用于客户端站点上使用常见Web浏览器的项目。 What we now need is a webserver that feeds our requirements. 我们现在需要的是一个满足我们需求的网络服务器。 These are: 这些是:

  • written in Java or PHP since these are the languages which currently are used and mastered by all the programmers in the project. 用Java或PHP编写的,因为这些是当前项目中所有程序员使用和掌握的语言。 Since it seems that there are no promising PHP implementations yet, I tend to concentrate on the Java site. 由于似乎还没有有前途的PHP实现,我倾向于专注于Java站点。
  • as fast as possible. 尽可能快。 We don't expect too heavy usage in production but we need to be able to synch two browsers on independent host in nearly real-time. 我们不希望在生产中使用过多,但我们需要能够几乎实时地在独立主机上同步两个浏览器。
  • easy expandable. 易于扩展。 We will need to implement our own protocol on top of the websockets so we would like the most possible flexibility. 我们需要在websockets之上实现我们自己的协议,因此我们希望获得最大的灵活性。
  • easy to use, well documented and actively developed. 易于使用,文档齐全,积极开发。 Since we have to come to a first running implementation rather quickly and since I expect some changes in the developing people during the time, it would be great if it's not to hard to get into the server programming. 由于我们必须相当快地进行第一次运行实现,并且因为我期望在此期间发展中人员发生一些变化,所以如果不是很难进入服务器编程就会很棒。

I already had a look on some servers/frameworks which look promising, eg Jetty, Netty and jWebSocket. 我已经看过一些看起来很有前景的服务器/框架,例如Jetty,Netty和jWebSocket。 I also found some older discussions of this topic. 我还发现了一些关于这个主题的旧讨论。 However, I would be glad about some current experiences or recommendations of those of you who already have used Java (or PHP) to work with Websockets. 但是,对于那些已经使用过Java(或PHP)来处理Websockets的人来说,我会很高兴。 Is there some implementation which is especially well-fitting or one that we absolutely shouldn't use? 是否有一些特别适合的实施或我们绝对不应该使用的实施?

Edit: For clarity: When I speak of implementing our own protocol on top of Websockets I mean having some kind of plugin mechanism so that we can use a Websocket to send XML-messages to the server and then use a plugin to interpret them into some server actions as we like. 编辑:为清楚起见:当我谈到在Websockets上实现我们自己的协议时,我的意思是拥有某种插件机制,以便我们可以使用Websocket将XML消息发送到服务器,然后使用插件将它们解释为一些我们喜欢的服务器动作。 I guess every server implementation also supports this but it would be good if it was not too difficult to write such plugins. 我想每个服务器实现也支持这一点,但如果编写这样的插件并不困难,那将会很好。

I don't have any experience with PHP so I'll give you my opinion for the Java (and python side). 我没有任何PHP经验,所以我会给你我对Java(和python方面)的看法。

For Java: 对于Java:

You have your very common and safe choice of Tomcat. 您拥有非常常见且安全的Tomcat选择。 It's one of the most actively developed servers, its open source, lots of support/help from its very large community, from what I've read (but not tested) it can be fairly scalable and it also has a very mature console to monitor different metrics for your website. 它是最活跃开发的服务器之一,它的开源,来自其庞大社区的大量支持/帮助,从我读过的(但未经过测试)它可以相当可扩展,它还有一个非常成熟的控制台来监控您网站的不同指标。

You also have other choices such as Caucho's Resin, who have a very small yet smart team who actively develop their webserver. 您还有其他选择,例如Caucho的Resin,他们拥有一个非常小而聪明的团队,他们积极开发他们的网络服务器。 Their new heartbeat service allows a good degree of scalability (again from what I've read). 他们新的心跳服务允许很好的可扩展性(再次从我读过的内容)。

And then you also have Google's appengine which is all about scalability. 然后你还有谷歌的引擎,这是关于可扩展性的。 Their API (for both, the server and client side) has started to focus on realtime web applications so it's a bit easier to for creating high performance web applications without having to worry about the server related optimization that you often have to make with other servers. 他们的API(服务器和客户端)已开始专注于实时Web应用程序,因此创建高性能Web应用程序更容易,而不必担心您经常需要与其他服务器进行的服务器相关优化。 They have APIs for creating "channels" between the server and client side for very realtime applications. 它们具有用于在非常实时的应用程序中在服务器和客户端之间创建“通道”的API。 The AppEngine team also has a new MapReduce API for analyzing data quickly/efficiently. AppEngine团队还有一个新的MapReduce API,用于快速/高效地分析数据。 For these reasons and the personal opinion that they are pioneering new web technologies/standards, I'm personally been leaning towards AppEngine. 出于这些原因以及他们开创新网络技术/标准的个人观点,我个人一直倾向于AppEngine。 It's free if you're keeping cpu/data usuage low but if you need full scale deployment it does start to get pricey so do research. 它是免费的,如果你保持低CPU的数据/数据,但如果你需要全面部署,它确实开始变得昂贵,所以做研究。 If your project is more for fun/school, its free quotas are enough and all its development tools/APIs are free so it's perfect. 如果您的项目更适合娱乐/学校,它的免费配额就足够了,它的所有开发工具/ API都是免费的,所以它是完美的。

For Python: 对于Python:

I'm more Java than Python, but Python is definitely a great language and very very very easy to learn. 我的Java比Python更多,但Python绝对是一门很棒的语言,而且非常容易学习。 And the reason I'm recommending Python for consideration here is because AppEngine also allows developers the choice of Python. 我之所以推荐使用Python,是因为AppEngine还允许开发人员选择Python。 The author/creater of the Python language is now on the AppEngine team so, even though the Python and Java APIs are pretty much exactly the same, they sometimes have new/better APIs for Python. Python语言的作者/创建者现在在AppEngine团队中,因此,即使Python和Java API几乎完全相同,他们有时也会为Python提供新的/更好的API。 For example, I think the datastore API offered with Python is a bit easier and optimized for the Google datastore. 例如,我认为使用Python提供的数据存储区API更容易,并针对Google数据存储区进行了优化。 Also, since you'd be using python, you can use Django with AppEngine. 此外,由于您将使用python,您可以将Django与AppEngine一起使用。

The second choice that I've recently become aware of is the tornado web server which was developed by FriendFeed and then bought and used by Facebook. 我最近意识到的第二个选择是龙卷风网络服务器,由FriendFeed开发,然后由Facebook购买和使用。 It's also actively developed. 它也在积极发展。 But the reason I bring this up is that Tornado's focus, much like AppEngine's, is high web application performance and scalability. 但我提出这个问题的原因是Tornado的重点,就像AppEngine一样,是高Web应用程序性能和可伸缩性。 I have no experience with it but I've become interested in its technology simply because no one can contest that Facebook requires a very high performance/scalable web server. 我没有经验,但我对它的技术感兴趣只是因为没有人可以质疑Facebook需要一个非常高性能/可扩展的Web服务器。

Some last thoughts: 最后一点想法:

In general you'll find that it isn't very difficult to build your own protocol on top of the APIs provided from most web servers (even Asp.NET MVC). 一般来说,你会发现在大多数Web服务器(甚至是Asp.NET MVC)提供的API之上构建自己的协议并不是很困难。 But from what I've been able to test around with AppEngine, it really focuses on being flexible on what kind of protocol is build on top of it. 但是从我用AppEngine测试的内容来看,它真正专注于灵活地构建基于什么样的协议。 To me, its pretty much just feels like a RPC server which which works on top of HTTP. 对我而言,它几乎就像一个在HTTP之上工作的RPC服务器。 And that becomes even more apparent if you use Python just because of some of the language constructs. 如果你因为一些语言结构而使用Python,那就更加明显了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM