小编sam*_*777的帖子

Python 客户端不接收来自 Spring websocket 服务器的消息

该项目的目标是让 JVM(Kotlin)服务器和 Python 客户端通过 websocket 相互通信。服务器必须向客户端发送更新,客户端将处理这些更新。

服务器是一个 Spring Boot 应用程序,运行 Spring Boot websocket 服务器。客户端现在只是一个 Python 脚本,运行 websocket-client 来连接到服务器。

什么工作:

  • 项目清单
  • 客户端可以连接到服务器
  • 客户端可以连接到服务器上的主题(使用 STOMP)
  • 客户端可以向服务器发送消息,服务器接收并处理该消息
  • 服务器可以在 websocket 上发送消息

什么不起作用:

  • 客户端没有收到来自服务器的消息

我已经通过连接到 websocket.org (ws://echo.websocket.org) 的回显服务器尝试了客户端的接收部分,并且客户端从服务器接收回显消息。所以在我看来,问题不在客户端。


代码时间。

Kotlin 服务器: 用于创建 websocket 服务器的代码:

package nl.sajansen.screenchangenotifierserver

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Configuration
import org.springframework.messaging.handler.annotation.MessageMapping
import org.springframework.messaging.simp.SimpMessagingTemplate
import org.springframework.messaging.simp.config.MessageBrokerRegistry
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Controller
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker
import org.springframework.web.socket.config.annotation.StompEndpointRegistry
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
import java.time.Instant
import java.time.format.DateTimeFormatter


@Configuration
@EnableWebSocketMessageBroker
class WebSocketConfig : WebSocketMessageBrokerConfigurer {
    override fun registerStompEndpoints(registry: StompEndpointRegistry) {
        registry.addEndpoint("/ws").setAllowedOrigins("*")
    }

    override …
Run Code Online (Sandbox Code Playgroud)

python java spring websocket kotlin

5
推荐指数
1
解决办法
1171
查看次数

标签 统计

java ×1

kotlin ×1

python ×1

spring ×1

websocket ×1