java-websocket

android中的websocket 应用

时光怂恿深爱的人放手 提交于 2020-04-28 02:58:56
websocket 在实际的应用中不仅仅能做聊天应用,还可以利用websocket长连接保持数据的实时更新以及信息的推送。 websocket 的实现的关键点 第一个 :首先需要引入 java-websocket.jar 包, 这里我使用的版本时1.3.1。 接下来就开始了,不同的业务有不同的需求,我们根据业务需求封装一下websocket 请求 在runable中实例websocket对象,并在四个回掉函数中构建自己的业务逻辑, 接着定义send方法发送请求 ,定义一个接口用于接收服务端返回的数据 。 其他的例如destory和开启线程方法就不多赘述。 第二 :因为我们需要websocket保持与服务端的连接,不仅仅在程序运行时,当锁屏以及程序后台时都需要获取服务端推送的信息,这时候我们就需要把websocket运行在service上了。 service 与程序交互则通过广播来完成。 在服务类中注册一个广播接收器和广播。当接收到数据之后在onMessage方法中处理,之后再有广播发送到客户端 。 接下来我们还需要定义一个中间广播类,用于接收service返回的信息到页面 ,以及一个接口用于页面的数据获取 到此整体的思路以及完成。 使用的话很简单,先实例一个中间广播类对象然后发送请求 ,在实现接口 用于处理对应的业务逻辑。 websocket核心:重连 拉起 心跳 解析 消息转发

Where does @serverendpoint path get mapped (Websockets)

坚强是说给别人听的谎言 提交于 2020-02-25 23:06:35
问题 I have the following @serverendpoint path for a websocket that I am using with the spring framework: @ServerEndpoint(value="/serverendpoint", configurator = SpringConfigurator.class) My first question is say I have a website with the url www.example.com . Where does the serverendpoint with path serverendpoint get mapped? Can I access my serverendpoint at wss://example.com:$PORT/currentpage.html/serverendpoint ? Or is this the wrong way. I have a Wildfly 10 server running. Based on another SO

How To Send Request Header To Jetty WebSocket From JavaScript Client

倾然丶 夕夏残阳落幕 提交于 2020-01-06 14:12:44
问题 How To Send Request Header To Jetty WebSocket From JavaScript Client ? What I am doing ? At Client Side. Need To add service name and service version in request header at client side Send to server At Server Side. Identify the service from the request header Using that create corresponding input translator (using GSON) Create service input using that translator Call the service. I can use org.eclipse.jetty.websocket.api.annotations.WebSocket as to get service name and version at server side.

Using Java Websocket API Implementation without a Web-Server

百般思念 提交于 2020-01-04 05:50:57
问题 Is it possible to implement a custom WebSocket app in Java without having to run it on a Web-Server like GlassFish, Tomcat, Jetty etc? I intend to develop a very custom-tailored App and would like to implement my own way to manage threads, monitoring, load balance, messaging and stuff like that. (compared with e.g. Java TCP’s ServerSocket ) I know there are Tyrus containers such as Grizzly integration for standalone server and Servlet support and here is Jetty as well, but I am not sure if

How to call @SendTo from Normal Request Call i.e @RequestMapping

谁说我不能喝 提交于 2019-12-31 13:28:10
问题 I have implemented Web Socket using Spring MVC and it is working fine for me i.e work from one browser to another browser which is open for those socket using this code. @MessageMapping("/hello") @SendTo("/topic/greetings") public HelloMessage greeting(HelloMessage message) throws Exception { Thread.sleep(3000); // simulated delay return message; } Can any one help me for who to call @SendTo("/topic/greetings") from normal api controller.I have try using this but it is not working for me

Web Socket Client not working in Tomcat

倖福魔咒の 提交于 2019-12-25 03:39:51
问题 I am trying to run a Web socket client under the context of Tomcat. So the scenario is, I have a Websocket Server Endpoint deployed on Tomcat, as part of App-1. App-2, which is also deployed on Tomcat (obviously under different context root), want to send a message. The class in App-2 works fine, if I run it as a stand alone from a main method. But it gives the below error, when it runs under context of tomcat. (I am using Tyrus 1.9 as JSR-356 impl) java.util.ServiceConfigurationError: javax

Prevent Tomcat from sending header “Connection: close”

↘锁芯ラ 提交于 2019-12-24 22:19:04
问题 My Tomcat Websocket Server has the attribute "Connection" double in the reply header for connections via https: "upgrade" and "close". Not for connections via http, only "upgrade" here. This will cause Safari to disconnect. How can I prevent "Connection: close" from appearing in the header? Connector configuration : <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads=

What are the available Java EE Websockets implementations?

笑着哭i 提交于 2019-12-23 22:36:39
问题 For the JSR 356 - Java API for WebSocket i know the reference implementation is Tyrus. Are there any others? If not, then i guess Tyrus is the implementation in all Application Servers (Glassfish, JBossAS/Wildfly etc...) 回答1: As far as I know, there are a few JSR 356 Java API for WebSocket implementations besides Tyrus (the reference implementation): Apache Tomcat Jetty Undertow used by WildFly Glassfish is the Java EE reference implementation and uses Tyrus. According to my researches: IBM

Incoming buffer size cannot be set to Tyrus client

有些话、适合烂在心里 提交于 2019-12-23 19:55:51
问题 I trying to transfer a file bigger than 4M via WebSocket. I'm using org.glassfish.tyrus:tyrus-server:1.13.1 and org.glassfish.tyrus:tyrus-container-grizzly-server:1.13.1 as dependencies. By default the incoming buffer size is about 4M (see: 8.4. Incoming buffer size). The documentation clearly says what needs to be done if I want to increase the size of the file but still can not change the incoming buffer size. Here is the essence of what I'm trying to do: CountDownLatch messageLatch = new

Spring Websocket Configuration: using WebSocketMessageBrokerConfigurationSupport and WebSocketConfigurer together - how?

只愿长相守 提交于 2019-12-23 19:22:14
问题 I am configuring currently my Spring Websocket using the class public class WebSocketConfig extends WebSocketMessageBrokerConfigurationSupport now I came across the advice Spring STOMP Websockets: any way to enable permessage-deflate on server side? that makes use of public class SampleJettyWebSocketsApplication implements WebSocketConfigurer and overrides @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) and offers @Bean public DefaultHandshakeHandler