parent
b9edde2fd2
commit
3552a70bf2
26 changed files with 139 additions and 219 deletions
@ -1,47 +0,0 @@ |
||||
package com.lq.code.WebSocket; |
||||
|
||||
import org.springframework.web.socket.*; |
||||
|
||||
/** |
||||
* Created by qi_liang on 2018/6/13. |
||||
*/ |
||||
public abstract class AbstraceWebSocketHandler implements WebSocketHandler { |
||||
|
||||
@Override |
||||
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception { |
||||
if (message instanceof TextMessage){ |
||||
handleTextMessage(session, (TextMessage) message); |
||||
} |
||||
else if (message instanceof BinaryMessage){ |
||||
handleBinaryMessage(session, (BinaryMessage) message); |
||||
} |
||||
else if (message instanceof PongMessage){ |
||||
handlPongMessage(session, (PongMessage) message); |
||||
} else { |
||||
throw new IllegalStateException("Unexpected WebSocket message type"+message); |
||||
} |
||||
} |
||||
|
||||
protected void handleTextMessage(WebSocketSession session,TextMessage message)throws Exception{ |
||||
|
||||
} |
||||
|
||||
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message)throws Exception{ |
||||
|
||||
} |
||||
protected void handlPongMessage(WebSocketSession session,PongMessage message)throws Exception{ |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void handleTransportError(WebSocketSession session, Throwable throwable) throws Exception { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception { |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -1,28 +0,0 @@ |
||||
package com.lq.code.WebSocket; |
||||
|
||||
import org.springframework.web.socket.CloseStatus; |
||||
import org.springframework.web.socket.TextMessage; |
||||
import org.springframework.web.socket.WebSocketSession; |
||||
import org.springframework.web.socket.handler.TextWebSocketHandler; |
||||
|
||||
/** |
||||
* Created by qi_liang on 2018/6/13. |
||||
*/ |
||||
public class CommoditySocket extends TextWebSocketHandler { |
||||
|
||||
@Override |
||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception { |
||||
System.out.println("open ......"); |
||||
} |
||||
|
||||
@Override |
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { |
||||
System.out.println("Close ........"); |
||||
} |
||||
|
||||
@Override |
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { |
||||
super.handleTextMessage(session, message); |
||||
System.out.println("接受到的消息是"+message.getPayload()); |
||||
} |
||||
} |
@ -1,17 +0,0 @@ |
||||
package com.lq.code.WebSocket; |
||||
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; |
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; |
||||
|
||||
/** |
||||
* Created by qi_liang on 2018/4/1. |
||||
*/ |
||||
public class MyWebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer { |
||||
|
||||
|
||||
@Override |
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) { |
||||
|
||||
} |
||||
} |
@ -1,20 +0,0 @@ |
||||
package com.lq.code.WebSocket; |
||||
|
||||
import org.springframework.web.socket.CloseStatus; |
||||
import org.springframework.web.socket.WebSocketMessage; |
||||
import org.springframework.web.socket.WebSocketSession; |
||||
|
||||
/** |
||||
* Created by qi_liang on 2018/6/13. |
||||
*/ |
||||
public interface WebSorketHandler { |
||||
|
||||
void alfterConeectionEstablished(WebSocketSession session)throws Exception; |
||||
|
||||
void handlMessage(WebSocketSession session, WebSocketMessage message)throws Exception; |
||||
|
||||
void handlTransportError(WebSocketSession session, CloseStatus closeStatus)throws Exception; |
||||
|
||||
boolean supportsPartialMessages(); |
||||
|
||||
} |
@ -1,16 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:websocket="http://www.springframework.org/schema/websocket" |
||||
xmlns="http://www.springframework.org/schema/beans" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans |
||||
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd |
||||
http://www.springframework.org/schema/websocket |
||||
http://www.springframework.org/schema/websocket/spring-websocket.xsd "> |
||||
|
||||
<websocket:handlers> |
||||
<websocket:mapping path="/marcohandler" handler="marcoHandler"/> |
||||
</websocket:handlers> |
||||
|
||||
<bean id="marcoHandler" class="com.lq.code.WebSocket.MarcoHandler"/> |
||||
|
||||
</beans> |
Loading…
Reference in new issue