From 1cdcd913ea6614478746f8e1fea5d8c6d49c145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=B0=E5=B9=B3=E7=BA=BF?= <22250530@qq.com> Date: Wed, 28 Oct 2015 09:42:12 +0800 Subject: [PATCH] --- .../redkale/net/client/WebSocketClient.java | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/android-jdk6-redkale/src/com/wentch/redkale/net/client/WebSocketClient.java b/android-jdk6-redkale/src/com/wentch/redkale/net/client/WebSocketClient.java index 0c121f393..5b82c0033 100644 --- a/android-jdk6-redkale/src/com/wentch/redkale/net/client/WebSocketClient.java +++ b/android-jdk6-redkale/src/com/wentch/redkale/net/client/WebSocketClient.java @@ -9,6 +9,7 @@ import com.wentch.redkale.util.*; import java.io.*; import java.net.*; import java.util.*; +import java.util.concurrent.*; import javax.net.ssl.*; /** @@ -27,6 +28,8 @@ public class WebSocketClient { private Socket socket; + private final Map attributes = new ConcurrentHashMap(); + private WebSocketClient(URI uri, Map headers0) { this.uri = uri; if (headers0 != null) this.headers.putAll(headers0); @@ -81,6 +84,66 @@ public class WebSocketClient { } public static void main(String[] args) throws Exception { - System.out.println(new URI("wss://talk.3wyc.com/pipes/ws/listen?test=aa").getQuery()); + URI uri = new URI("ws://10.28.2.207/pipes/ws/listen?test=aa"); + WebSocketClient client = WebSocketClient.create(uri); + client.connect(); + System.out.println(); + } + + public void onConnected() { + } + + public void onMessage(String text) { + } + + public void onPing(byte[] bytes) { + } + + public void onPong(byte[] bytes) { + } + + public void onMessage(byte[] bytes) { + } + + public void onFragment(String text, boolean last) { + } + + public void onFragment(byte[] bytes, boolean last) { + } + + public void onClose(int code, String reason) { + } + + /** + * 获取当前WebSocket下的属性 + *

+ * @param + * @param name + * @return + */ + @SuppressWarnings("unchecked") + public final T getAttribute(String name) { + return (T) attributes.get(name); + } + + /** + * 移出当前WebSocket下的属性 + *

+ * @param + * @param name + * @return + */ + public final T removeAttribute(String name) { + return (T) attributes.remove(name); + } + + /** + * 给当前WebSocket下的增加属性 + *

+ * @param name + * @param value + */ + public final void setAttribute(String name, Object value) { + attributes.put(name, value); } }