Skip to content

Commit

Permalink
Merge pull request codebutler#13 from pefoley2/master
Browse files Browse the repository at this point in the history
add isConnected method and remove incorrect annotations.
  • Loading branch information
koush committed Apr 8, 2013
2 parents 878842d + 1174d7e commit 84119d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/com/codebutler/android_websockets/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class WebSocketClient {
private Handler mHandler;
private List<BasicNameValuePair> mExtraHeaders;
private HybiParser mParser;
private boolean mConnected;

private final Object mSendLock = new Object();

Expand All @@ -47,8 +48,9 @@ public static void setTrustManagers(TrustManager[] tm) {

public WebSocketClient(URI uri, Listener listener, List<BasicNameValuePair> extraHeaders) {
mURI = uri;
mListener = listener;
mListener = listener;
mExtraHeaders = extraHeaders;
mConnected = false;
mParser = new HybiParser(this);

mHandlerThread = new HandlerThread("websocket-thread");
Expand Down Expand Up @@ -119,17 +121,21 @@ public void run() {

mListener.onConnect();

mConnected = true;

// Now decode websocket frames.
mParser.start(stream);

} catch (EOFException ex) {
Log.d(TAG, "WebSocket EOF!", ex);
mListener.onDisconnect(0, "EOF");
mConnected = false;

} catch (SSLException ex) {
// Connection reset by peer
Log.d(TAG, "Websocket SSL error!", ex);
mListener.onDisconnect(0, "SSL");
mConnected = false;

} catch (Exception ex) {
mListener.onError(ex);
Expand All @@ -147,6 +153,7 @@ public void run() {
try {
mSocket.close();
mSocket = null;
mConnected = false;
} catch (IOException ex) {
Log.d(TAG, "Error while disconnecting", ex);
mListener.onError(ex);
Expand All @@ -164,6 +171,10 @@ public void send(byte[] data) {
sendFrame(mParser.frame(data));
}

public boolean isConnected() {
return mConnected;
}

private StatusLine parseStatusLine(String line) {
if (TextUtils.isEmpty(line)) {
return null;
Expand Down

0 comments on commit 84119d1

Please sign in to comment.