使用JSR365规范构建J2EE websocket服务端和客户端应用

JSR365是java制定的websocket编程规范,属于Java EE 7的一部分。下面这段描述摘录自官网对JSR365的说明:

JSR 356, Java API for WebSocket, specifies the API that Java developers can use when they want to integrate WebSockets into their applications—both on the server side as well as on the Java client side. Every implementation of the WebSocket protocol that claims to be compliant with JSR 356 must implement this API. As a consequence, developers can write their WebSocket-based applications independent of the underlying WebSocket implementation. This is a huge benefit, because it prevents a vendor-lock and allows for more choices and freedom of libraries and application servers.

JSR 356 is a part of the upcoming Java EE 7 standard; hence, all Java EE 7–compliant application servers will have an implementation of the WebSocket protocol that adheres to the JSR 356 standard. Once they are established, WebSocket client and server peers are symmetrical. The difference between a client API and a server API is, therefore, minimal. JSR 356 defines a Java client API as well, which is a subset of the full API required in Java EE 7.

websocket和socket一样,既有客户端编程,也有服务端编程,JSR365制定了websocket客户端和服务端编程常用的API。我的另一篇文章介绍了使用Tomcat自己的websocket也能够实现web推送,但是那篇文章中的代码只能运行在tomcat容器。我们使用JSR365编写的websocket程序,能够在所有web容器中运行,只要这个容器实现了J2EE 7规范。我使用的是Tomcat7.0.62,这个版本的Tomcat实现了J2EE 7规范。


为了使用JSR365,我们需要在pom.xml加入编译期的依赖:

<dependency>
	<groupId>javax.websocket</grou
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值