sockjs

spring boot整合websocket

送分小仙女□ 提交于 2019-12-18 13:32:22
转载自: https://www.cnblogs.com/GoodHelper/p/7078381.html 一.WebSocket简单介绍   随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了。近年来,随着HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通信,扩展了浏览器与服务端的通信功能,使服务端也能主动向客户端发送数据。   我们知道,传统的HTTP协议是无状态的,每次请求(request)都要由客户端(如 浏览器)主动发起,服务端进行处理后返回response结果,而服务端很难主动向客户端发送数据;这种客户端是主动方,服务端是被动方的传统Web模式 对于信息变化不频繁的Web应用来说造成的麻烦较小,而对于涉及实时信息的Web应用却带来了很大的不便,如带有即时通信、实时数据、订阅推送等功能的应 用。在WebSocket规范提出之前,开发人员若要实现这些实时性较强的功能,经常会使用折衷的解决方法: 轮询(polling) 和 Comet 技术。其实后者本质上也是一种轮询,只不过有所改进。   轮询 是最原始的实现实时Web应用的解决方案。轮询技术要求客户端以设定的时间间隔周期性地向服务端发送请求,频繁地查询是否有新的数据改动。明显地,这种方法会导致过多不必要的请求,浪费流量和服务器资源。   Comet技术 又可以分为

Header in the response must not be the wildcard '*' when the request's credentials mode is 'include'

旧巷老猫 提交于 2019-12-18 03:52:06
问题 I'm using Auth0 for my user authentication to only allow logged in users to access a Spring (Boot) RestController . At this point I'm creating a real-time message functionality where users can send messages from the Angular 2 client ( localhost:4200 ) to the Spring server (localhost:8081) using stompjs and sockjs . When trying to create a Stomp-client and starting a connection I receive the following console-error: The value of the 'Access-Control-Allow-Origin' header in the response must not

Stomp over socket using sockjs can't connect with Spring 4 WebSocket

大城市里の小女人 提交于 2019-12-17 19:44:49
问题 Trying to use Spring 4 WebSocket with STOMP over socket using sockjs. And i faced a problem. My configuration: websocket.xml - part of spring context <websocket:message-broker application-destination-prefix="/app"> <websocket:stomp-endpoint path="/ws"> <websocket:sockjs/> </websocket:stomp-endpoint> <websocket:simple-broker prefix="/topic"/> </websocket:message-broker> Controller code: @MessageMapping("/ws") @SendTo("/topic/ws") public AjaxResponse hello() throws Exception { AjaxResponse

Spring Websocket and 404 status on connection

邮差的信 提交于 2019-12-17 19:25:13
问题 In a working Spring MVC 4.0.2 project running under Tomcat 7.0.50, I'm trying to implement Spring Websocket with simple broker and sockjs stomp endpoint, following the official reference. So, in the contextConfigLocation (DistpacherServlet property) I've add a value "websocket-config.xml" which contains: > <websocket:message-broker application-destination-prefix="/app" > > <websocket:stomp-endpoint path="/monitor"> > <websocket:sockjs /> > </websocket:stomp-endpoint> > <websocket:simple

How to unmarshal an escaped JSON string in Go?

こ雲淡風輕ζ 提交于 2019-12-17 15:39:47
问题 am using Sockjs with Go, but when the javascript client send json to the server it escapes it, and send's it as a []byte. i'm trying to figure out how to parse the json, so that i can read the data. but i get this error. json: cannot unmarshal string into Go value of type main.Msg How can i fix this? html.UnescapeString() have no effect :/ val, err := session.ReadMessage() if err != nil { break } var msg Msg err = json.Unmarshal(val, &msg) fmt.Printf("%v", val) fmt.Printf("%v", err) type Msg

Path variables in Spring WebSockets @SendTo mapping

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 08:20:18
问题 I have, what I think to be, a very simple Spring WebSocket application. However, I'm trying to use path variables for the subscription as well as the message mapping. I've posted a paraphrased example below. I would expect the @SendTo annotation to return back to the subscribers based on their fleetId . ie, a POST to /fleet/MyFleet/driver/MyDriver should notify subscribers of /fleet/MyFleet , but I'm not seeing this behavior. It's worth noting that subscribing to literal /fleet/{fleetId}

Which websocket library to use with Node.js? [closed]

青春壹個敷衍的年華 提交于 2019-12-17 02:01:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Currently there is a plethora of websocket libraries for node.js, the most popular seem to be: https://github.com/Worlize/WebSocket-Node https://github.com/einaros/ws https://github.com/LearnBoost/engine.io https://github.com/learnboost/socket.io https://github.com/sockjs However I can't find any solid concrete

Preventing random 'RuntimeError: Event loop is closed' in automated test

折月煮酒 提交于 2019-12-14 03:12:50
问题 Referring to: How do I avoid the loop argument I am trying to write a SockJS client in python, and I would like that code to have some automated tests. Here is the code: from urllib.parse import urlparse import websockets class SockJsClient: def __init__(self, base_url): self.base_url = urlparse(base_url) async def connect(self): uri = self.base_url.geturl() + "/websocket" self.websocket = await websockets.connect(uri) async def disconnect(self): await self.websocket.close() and here are my

How do I close a sockjs connection on the server side?

随声附和 提交于 2019-12-13 02:57:42
问题 So, every time I refresh the page, it seems like sockjs is creating a new connection. I am saving every message to my mongodb on every channel.onmessage, so if I refresh my page 7 times and send a message, I would save 7 messages of the same content into my mongodb. This is very problematic because when I retrieve those messages when I go into the chat room, to see the log, I would see bunch of duplicate messages. I want to keep track of all connections that are 'active', and if a user tries

Uncaught Error: Incompatible SockJS! - Angular 2 CLI

假装没事ソ 提交于 2019-12-12 19:18:01
问题 I have been getting the error: 'Uncaught Error: Incompatibile SockJS! Main site uses: "1.1.1", the iframe: "1.0.1".' I was not getting this error until I added the following code to a service: *COMPONENT* this.dataService.getData(1,null).subscribe( result => this.allSCATSsites = result.json(), () => console.log("Failed..."), () => this.processSites() ); *SERVICE* getData(functionindex: number, dataarray) { let headers = new Headers(); headers.append('Content-Type', 'application/json'); return