nv-websocket-client是一个用 Java 编写的新 WebSocket 客户端库。它支持wss并且只需要 Java SE 1.5,因此它甚至可以在 Android 上运行。
(2015-05-06 发布)的大小nv-websocket-client-1.3.jar
为 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.");
}
}
博客
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/
马文
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>1.3</version>
</dependency>