可以通过JAVA SDK 将服务器作为一个client连接到leancloud吗

  public static void main(String[] args) {

        AVIMConversation conversation = null;

        //初始化
        AVOSCloud.initialize("xxxxxx", "xxxxx","xxxxxx");
        

        //开启调试日志
        AVOSCloud.setLogLevel(AVLogger.Level.DEBUG);

        //用户Tom
        AVIMClient tom = AVIMClient.getInstance("Tom");

        tom.open(new AVIMClientCallback() {
            @Override
            public void done(AVIMClient client, AVIMException e) {
                if (e == null) {
                    // 成功打开连接
                    System.out.println("连接成功");
                }else{

                }
            }
        });

        tom.createConversation(Arrays.asList("Jerry"), "Tom & Jerry", null, false, true,
            new AVIMConversationCreatedCallback() {
                @Override
                public void done(AVIMConversation conversation, AVIMException e) {
                    if(e == null) {
                       conversation = conversation;
                    }
                }
            });

        AVIMTextMessage msg = new AVIMTextMessage();
        msg.setText("Jerry,起床了!");

        // 发送消息
        if(conversation == null)
            return ;
        conversation.sendMessage(msg, new AVIMConversationCallback() {
            @Override
            public void done(AVIMException e) {
                if (e == null) {
                    System.out.println("Tom & Jerry,发送成功!");
                }
            }
        });
    }

结果:
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
详细: openClient...
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
详细: add request cache. client=Tom, conv=null, request=-65535
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
严重: session error:java.lang.IllegalStateException: Connection Lost
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
严重: session error:java.lang.IllegalStateException: Connection Lost
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
详细: enter onOperationCompleted with clientId=Tom, convId=null, requestId=-65535, operation=CLIENT_OPEN
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
详细: createConversation...
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
详细: add request cache. client=Tom, conv=null, request=-65534
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
严重: session error:java.lang.RuntimeException: Connection Lost
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
严重: session error:java.lang.RuntimeException: Connection Lost
一月 02, 2020 4:12:38 下午 cn.leancloud.logging.SimpleLogger internalWriteLog
详细: enter onOperationCompleted with clientId=Tom, convId=null, requestId=-65534, operation=CONVERSATION_CREATION

有没有大佬知道

理论上是可行的,但是部分 API 是针对 Android 环境和移动端应用的场景设计的,在纯 Java 环境下使用不太顺。您遇到问题可以在论坛反馈。

这个问题有解决吗?我也遇到了同样的问题

在纯 java 环境下使用即时通讯的功能,需要先手动建立连接,详见文档:https://leancloud.cn/docs/sdk_setup-java.html#hash-591683938