最小的java8 nio安全websocket客户端(wss) [英] minimal java8 nio secure websocket client (wss)

查看:525
本文介绍了最小的java8 nio安全websocket客户端(wss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很长时间才找到一个简单的java websocket客户端,可以使用wss而且不会乱七八糟......

I've spent quite some time to find simple java websocket client that could work with wss and wont be a mess...

我试过 https://github.com/TooTallNate/Java-WebSocket

在他的descirbes中添加了依赖,复制了SSLClientExample.java以使用websocket.org echo服务器进行测试,但是在第84行遇到编译错误没有这样的方法setSocket()...(卡在这里)

added dependency as he descirbes, copied the SSLClientExample.java to test it with websocket.org echo server, but got compile error at line 84 no such method setSocket()... (stuck here)

我试过tyrus(似乎这是一个由oracle直接开发的大型库)但似乎我需要运行一些appserver(websocket容器)才能使用它...

I tried tyrus (seems this is a big library developed directly by oracle) but it seems i need to have some appserver running (websocket container) to be able to use it...

我想知道对于那些需要netty或glassfish或grizly的websockets来说这么困难吗?

I wonder whats so difficult about websockets that one needs to have netty or glassfish or grizly for that?

我认为可以使用SSLEngine(wss)和纯java sdk实现一个...有什么我不知道的websockets吗? (我想它非常像普通的插座)

I think its possible to implement one using SSLEngine (wss) and pure java sdk... is there something i dont know about websockets? ( i imagine it very much like ordinary sockets)

推荐答案

nv-websocket-client 是一个用Java编写的新WebSocket客户端库。它支持 wss ,只需要Java SE 1.5,因此它甚至可以在Android上运行。

nv-websocket-client is a new WebSocket client library written in Java. It supports wss and requires just Java SE 1.5, so it can run even on Android.

nv的大小-websocket-client-1.3.jar (2015-05-06发布)为62,854字节,不需要任何外部依赖。

The size of nv-websocket-client-1.3.jar (released on 2015-05-06) is 62,854 bytes and it does not require any external dependencies.

下面是一个wss示例。

Below is a "wss" example.

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

JavaDoc

http://takahikokawasaki.github.io/nv-websocket-client/

Maven

<dependency>
    <groupId>com.neovisionaries</groupId>
    <artifactId>nv-websocket-client</artifactId>
    <version>1.3</version>
</dependency>

这篇关于最小的java8 nio安全websocket客户端(wss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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