vac*_*ach 9 java networking websocket java-8 tyrus
我花了很长时间才找到一个简单的java websocket客户端,可以使用wss而不会乱七八糟......
我试过https://github.com/TooTallNate/Java-WebSocket
他在descirbes中添加了依赖,复制了SSLClientExample.java以使用websocket.org echo服务器进行测试,但是在第84行遇到编译错误没有这样的方法setSocket()......(卡在这里)
我试过tyrus(似乎这是一个由oracle直接开发的大型库)但似乎我需要运行一些appserver(websocket容器)才能使用它...
我不知道对于那些需要使用netty或glassfish或grizly的websockets来说这么困难吗?
我认为可以使用SSLEngine(wss)和纯java sdk实现一个...有什么我不知道websockets?(我想它非常像普通的插座)
Tak*_*aki 19
nv-websocket-client是一个用Java编写的新WebSocket客户端库.它支持 wss并且只需要Java SE 1.5,因此它甚至可以在Android上运行.
nv-websocket-client-1.3.jar
(2015-05-06发布)的大小为62,854字节,不需要任何外部依赖项.
下面是一个"wss"示例.
import com.neovisionaries.ws.client.*;
public class HelloWSS
{
public static void main(String[] args) throws Exception
{
// Connect to "wss://echo.websocket.org" and send "Hello." to it.
// When a response from the WebSocket server is received, the
// WebSocket connection is closed.
new WebSocketFactory()
.createSocket("wss://echo.websocket.org")
.addListener(new WebSocketAdapter() {
@Override
public void onTextMessage(WebSocket ws, String message) {
// Received a response. Print the received message.
System.out.println(message);
// Close the WebSocket connection.
ws.disconnect();
}
})
.connect()
.sendText("Hello.");
}
}
Run Code Online (Sandbox Code Playgroud)
博客
WebSocket客户端库(Java SE 1.5 +,Android)
http://darutk-oboegaki.blogspot.jp/2015/05/websocket-client-library-java-se-15.html
GitHub
https://github.com/TakahikoKawasaki/nv-websocket-client
JavaDoc
http://takahikokawasaki.github.io/nv-websocket-client/
Maven的
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>1.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)