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.");
}
}
Maven的
com.neovisionaries
nv-websocket-client
1.3