Skip to content

Commit

Permalink
添加WebSocket的支持,以及实例
Browse files Browse the repository at this point in the history
  • Loading branch information
jwzha committed Dec 6, 2014
1 parent f50e308 commit fe676d9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Binary file added AndJie/libs/websocket.jar
Binary file not shown.
31 changes: 31 additions & 0 deletions AndJie/src/com/jwzhangjie/andbase/doc/WebSocketUsed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.jwzhangjie.andbase.doc;

import java.net.URI;
import java.net.URISyntaxException;

import org.java_websocket.drafts.Draft_17;

import com.jwzhangjie.andbase.net.JieWebSocket;

/**
* title: WebSocketUsed.java
* @author jwzhangjie
* Date: 2014-12-6 下午3:37:12
* version 1.0
* {@link http://blog.csdn.net/jwzhangjie}
* Description: JieWebSocket的简单使用,主要还是在JieWebSocket内容处理相关内容
*/
public class WebSocketUsed {

private JieWebSocket mJieWebSocket;

public WebSocketUsed() {
try {
mJieWebSocket = new JieWebSocket(new URI("url"), new Draft_17());
mJieWebSocket.connect();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}

}
56 changes: 56 additions & 0 deletions AndJie/src/com/jwzhangjie/andbase/net/JieWebSocket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.jwzhangjie.andbase.net;

import java.net.URI;
import java.util.Map;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.handshake.ServerHandshake;

/**
* title: JieWebSocket.java
* @author jwzhangjie
* Date: 2014-12-6 下午3:34:22
* version 1.0
* {@link http://blog.csdn.net/jwzhangjie}
* Description:与后台通过WebSocket通信的封装
*/
public class JieWebSocket extends WebSocketClient {

public JieWebSocket(URI serverUri, Draft draft) {
super(serverUri, draft);
}

public JieWebSocket(URI serverUri, Draft protocolDraft,
Map<String, String> httpHeaders, int connectTimeout) {
super(serverUri, protocolDraft, httpHeaders, connectTimeout);
}

public JieWebSocket(URI serverURI) {
super(serverURI);
}

@Override
public void onClose(int arg0, String arg1, boolean o) {

}

@Override
public void onError(Exception exception) {
exception.printStackTrace();
}

/**
* 接收后台发送的信息,格式自己定义
*/
@Override
public void onMessage(String msg) {

}

@Override
public void onOpen(ServerHandshake server) {

}

}

0 comments on commit fe676d9

Please sign in to comment.