简单(Java,Javascript)从Websockets开始 [英] Simple (Java, Javascript) start on Websockets

查看:123
本文介绍了简单(Java,Javascript)从Websockets开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Websockets上找到一个好的(最新的)Java Trail类型的开始教程,包括Javascript客户端代码和Java服务器代码(实际上可行)。在服务器端,如果我要做的就是创建一个简单的套接字服务器或类似的东西,请告诉我。到目前为止,我没有发现任何东西(虽然我用Google搜索了几个小时),提供了这样的必要基本信息(除了客户端,这显然非常容易)。



<我对使用现有的Websocket服务器系统不感兴趣(除了从简单教程中的简单复制粘贴开始)。如果你有兴趣,我会告诉你为什么在下面。



我有一个开源项目,它早在它开始之前一直在乞求HTML5(从最初开始许多年前的概念)。从Websockets获得双向通信而不是长轮询,永久帧等,对我来说似乎是一个胜利者。 (框架)软件的当前版本是 HLL 光 - 我的典型强调不要拖延额外的代码。它仅使用Java SE,但我打算使用EE通信构建版本。我现在可以轻松安装整个框架,为手机等小型设备上的应用程序组件提供空间。


  1. 我想要最少的代码。

  2. 我为理解系统中的所有代码而感到自豪。

  3. 我认为如果你必须告诉它,那么新的开源项目就会死亡想要尝试它的人,他们必须下载并安装各种其他开源代码才能做到这一点。

  4. 我不希望我的代码在其他人的代码中发生变化。

  5. 如果我找到合适的文件,这真的不应该那么困难。

更新:我不再需要关于websockets的简单教程。我正在建立一个生产类websocket服务器,并有一个非常好的基于浏览器的客户端用于测试。我现在正在构建一个非基于浏览器的客户端。构建实现完整标准的多客户端websocket服务器并不简单,顺便说一句。 (事后看来 - 难怪我没有得到任何答案。)如果它将作为基于浏览器的客户端的独立服务器工作,它需要http(至少提供网页)和其他东西。对于胆小的人或没有时间投入的人来说,这不是一个项目。

解决方案

自首次发帖以来,我已经一直在构建我自己的WebSocket服务器。梦想所有这一切都很简单很快就过去了。然而,对于想要websocket服务器的人来说,我已经足够接近提及免费测试版中的发布一词。 (请注意,我只是提及这个词 - 我至少还需要几周的时间。)这是一款轻量级且速度惊人的多用户服务器。我最终会添加http支持,因此不需要其他服务器来传送网页(无论如何,WebSockets都是升级的http连接)。我还将添加HLL功能。首先,它将简化应用程序。虽然我一直致力于保持轻量级的地位,但这种整体组合已成为人生的抱负,我相信开发人员会发现从简单直接到大型复杂的分布式智能系统构建任何东西都是惊人的。



我使用了标准的最新版本,即最终草案版本,如果与最终标准不同,可能会非常接近;版本1.到目前为止,它适用于Chromium(Chrome dev)和Firefox。但是,WebKit中显然有一些代码可以为其他浏览器提供支持。我还没有尝试过。通过浏览器,我到目前为止已经建立了连接并来回传递短信(大小)。这就是我迄今为止发现的浏览器处理的全部内容。我支持非常大的文本消息实际上只用于文件传输以及HTML5本地存储功能。我还没试过。二进制传输可能会在某些时候连接到HTML5流媒体视频和音频,但到目前为止我还没有提及它。



我目前正致力于支持完整标准的Java客户端,包括ping和二进制传输,文件传输 - 整个蜡球。我需要的大部分内容已经为服务器及其echo应用程序构建,其中包括与客户端一样的消息发送。然后,我将重新审视我最早的一些工作,以便在添加新功能时以一种很好的方式进行概括。在我看来,在许多情况下,在应用程序中拥有一个或多个Java websocket客户端将是一件好事。它还将为Web浏览器提供全面的功能,无论何时它们都准备好了。



我也知道Opera在HTML5爱好者中很受欢迎。我实际上开始使用他们支持的标准版本,所以添加它应该不难。 (只是愚弄试图找到我的方式 - 并获得特定于该版本的工作。)我很想花时间为该版本提供支持,即使它应该在几个月内完全过时。只是Opera非常擅长其他HTML5的东西,并且有很多爱好者使用它。另一方面,他们主要在浏览器 - 客户端工作,我不知道他们是否会参与构建服务器端应用程序。


I would like to find a good (up-to-date) Java Trail type beginning tutorial on Websockets, with both Javascript client code and Java server code (that actually works). On the server side, if all I have to do is create a simple socket server or something like that, please tell. I have so far found nothing (although I've googled for hours) that provides the essential basic information like this (except on the client side, which is apparently very easy).

I'm not interested in using existing Websocket server systems (other than starting with a simple copy-paste from a simple tutorial). If you're interested, I'll tell you why below.

I have an open-source project that's been begging for HTML5 since long before it began (from its initial conception many years ago). Getting the two-way communication from Websockets as opposed to long-polling, forever-frames etc. looks like a winner to me. The current version of the (framework) software is HLL "light" - with my typical emphasis on not dragging in extra code. It uses Java SE only, although I intend to build version(s) using EE communications. I can at present easily install the whole framework with room to spare for application components on small devices like cell phones.

  1. I want minimum code.
  2. I pride myself on understanding all the code in the system.
  3. I think it's death to a new open-source project if you have to tell people who want to try it that they have to download and install all sorts of other open-source code to do it.
  4. I don't want my code subject to changes in somebody else's code.
  5. This really shouldn't be all that difficult - if I just find the right documentation.

UPDATE: I no longer need a simple tutorial on websockets. I'm well on my way to having built a production class websocket server and have a very nice browser-based client to use for testing. I am now building a non-browser-based client to go with it. Building a multi-client websocket server that implements the full standard isn't simple, btw. (In hindsight - it's no wonder I didn't get any answers.) And if it's going to work as a stand-alone server for browser-based clients, it needs http (to provide the web pages at least) and other stuff. Not a project for the faint of heart or someone with little time to put into it.

解决方案

Since first posting, I've been building my own WebSocket server. Dreams that all this would be simple quickly passed. I am however, getting close enough to mention the word "release" as in free Beta for anyone who wants a websocket server. (Notice I'm just "mentioning" the word - I'm still at least a couple of weeks away.) It's a multi-user server that's light-weight and screamingly fast. I'll eventually add http support so no other server will be needed for delivery of web pages (WebSockets are upgraded http connections anyway). I'll also be adding HLL functionality. First thing about that is that it will simplify application. Even though I've worked consistently to maintain "light-weight" status, this whole combination has been a life's ambition and I believe developers will find it amazing for building anything from simple and direct to large scale complex, distributed, intelligent systems.

I've used the most recent version of the standard, which is the final draft version, and will probably be very close if not the same as the final standard; version 1. So far, it works with Chromium (Chrome dev) and Firefox. There is however, apparently some code in their WebKit that provides support for other browsers. I haven't tried that yet. With the browser, I've so far made the connection and pass text messages (large and small) back and forth. That's all I've discovered so far that the browser handles. I take it support for very large text "messages" would really only be used for file transfer in conjunction with HTML5 local storage capabilities. I haven't tried that yet either. Binary transfers will likely be connected to HTML5 streaming video and audio at some point, but I haven't run across any mention of it so far.

I'm currently working on a Java client that will support the full standard, including pings and binary transfers, file transfers - the whole ball of wax. Most of what I need has already been built for the server and its "echo" application which includes message sending just like a client. I will then revisit some of my earliest work to generalize in a nice way when adding the new functionality. Having one or more Java websocket clients in applications will be a good thing in many cases, I think. And it'll give the the full capabilities for web browsers as well, whenever they're ready for it.

I also know that Opera is quite popular among HTML5 enthusiasts. I actually started using the version of the standard that they support so it shouldn't be difficult to add it. (Just fooling around trying to find my way - and got the stuff specific to that version working.) I'm seriously tempted to spend the time putting the support in for that version even though it should become totally obsolete within a few months. It's just that Opera is very good on the other HTML5 stuff and there's a large crowd of enthusiasts using it. On the other hand, they mostly work on the browser-client side, and I don't know if they'll get involved much on building server-side applications.

这篇关于简单(Java,Javascript)从Websockets开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆