Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ Then you can just add the latest version to your build.
compile "org.java-websocket:Java-WebSocket:1.3.6"
```


### Leiningen

``` bash
[org.java-websocket/java-websocket "1.3.6"]
```

Running the Examples
-------------------

Expand All @@ -79,10 +72,7 @@ The chat client is a simple Swing GUI application that allows you to send
messages to all other connected clients, and receive messages from others in a
text box.

In the example folder is also a simple HTML file chat client `chat.html`, which can be opened by any browser. If the browser natively supports the WebSocket API, then it's
implementation will be used, otherwise it will fall back to a
[Flash-based WebSocket Implementation](https://github.com/gimite/web-socket-js).

In the example folder is also a simple HTML file chat client `chat.html`, which can be opened by any browser.

Writing your own WebSocket Server
---------------------------------
Expand All @@ -99,7 +89,7 @@ Writing your own WebSocket Client

The `org.java_websocket.client.WebSocketClient` abstract class can connect to
valid WebSocket servers. The constructor expects a valid `ws://` URI to
connect to. Important events `onOpen`, `onClose`, `onMessage` and `onIOError`
connect to. Important events `onOpen`, `onClose`, `onMessage` and `onError`
get fired throughout the life of the WebSocketClient, and must be implemented
in **your** subclass.

Expand Down Expand Up @@ -129,8 +119,8 @@ Minimum Required JDK

`Java-WebSocket` is known to work with:

* Java 1.5 (aka SE 6)
* Android 1.6 (API 4)
* Java 1.6 and higher
* Android 4.0 and higher

Other JRE implementations may work as well, but haven't been tested.

Expand Down
69 changes: 45 additions & 24 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
<project default="all">
<target name="all" depends="doc,jar" />
<target name="all" depends="doc,jar" />

<target name="compile">
<mkdir dir="build/classes" />
<mkdir dir="build/examples" />
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
destdir="build/classes" target="1.6" source="1.6">
</javac>
<javac includeantruntime="false" srcdir="src/main/example/"
classpath="build/classes" destdir="build/examples" />
</target>
<target name="compile">
<mkdir dir="build/classes" />
<mkdir dir="build/examples" />
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
destdir="build/classes" target="1.6" source="1.6">
</javac>
<javac includeantruntime="false" srcdir="src/main/example/"
classpath="build/classes" destdir="build/examples" />
</target>

<target name="jar" depends="compile">
<mkdir dir="dist"/>
<jar destfile="dist/java_websocket.jar">
<fileset dir="build/classes" includes="**/*.class" />
</jar>
</target>
<target name="jar" depends="compile">
<mkdir dir="dist"/>
<jar destfile="dist/java_websocket.jar">
<fileset dir="build/classes" includes="**/*.class" />
</jar>
</target>

<target name="doc">
<delete dir="doc" />
<javadoc sourcepath="src/main/java" destdir="doc" />
</target>
<target name="compileAutobahn">
<mkdir dir="build/classes" />
<mkdir dir="build/examples" />
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
destdir="build/classes" target="1.6" source="1.6">
</javac>
<javac includeantruntime="false" debug="on" srcdir="src/test/java/org/java_websocket/example"
destdir="build/classes" target="1.6" source="1.6">
</javac>
</target>

<target name="clean">
<delete dir="build" />
<delete dir="dist" />
</target>
<target name="jarAutobahn" depends="compileAutobahn">
<mkdir dir="dist"/>
<jar destfile="dist/autobahnserver.jar">
<fileset dir="build/classes" includes="**/*.class" />
<manifest>
<attribute name="Main-Class" value="org.java_websocket.example.AutobahnServerTest"/>
</manifest>
</jar>
</target>

<target name="doc">
<delete dir="doc" />
<javadoc sourcepath="src/main/java" destdir="doc" />
</target>

<target name="clean">
<delete dir="build" />
<delete dir="dist" />
</target>

</project>
2 changes: 1 addition & 1 deletion src/main/java/org/java_websocket/WebSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void decode( ByteBuffer socketBuffer ) {
decodeFrames( socketBuffer );
}
} else {
if( decodeHandshake( socketBuffer ) ) {
if( decodeHandshake( socketBuffer ) && (!isClosing() && !isClosed())) {
assert ( tmpHandshakeBytes.hasRemaining() != socketBuffer.hasRemaining() || !socketBuffer.hasRemaining() ); // the buffers will never have remaining bytes at the same time

if( socketBuffer.hasRemaining() ) {
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/java_websocket/issues/AllIssueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

@RunWith(Suite.class)
@Suite.SuiteClasses({
org.java_websocket.issues.Issue609Test.class
org.java_websocket.issues.Issue609Test.class,
org.java_websocket.issues.Issue621Test.class,
org.java_websocket.issues.Issue580Test.class
})
/**
* Start all tests for issues
Expand Down
192 changes: 192 additions & 0 deletions src/test/java/org/java_websocket/issues/Issue580Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Copyright (c) 2010-2017 Nathan Rajlich
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package org.java_websocket.issues;

import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.framing.CloseFrame;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.server.WebSocketServer;
import org.java_websocket.util.SocketUtil;
import org.java_websocket.util.ThreadCheck;
import org.junit.Rule;
import org.junit.Test;

import java.net.InetSocketAddress;
import java.net.URI;
import java.util.concurrent.CountDownLatch;

public class Issue580Test {

@Rule
public ThreadCheck zombies = new ThreadCheck();

private void runTestScenario(boolean closeBlocking) throws Exception {
final CountDownLatch countServerDownLatch = new CountDownLatch( 1 );
int port = SocketUtil.getAvailablePort();
WebSocketServer ws = new WebSocketServer( new InetSocketAddress( port ) ) {
@Override
public void onOpen( WebSocket conn, ClientHandshake handshake ) {

}

@Override
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {

}

@Override
public void onMessage( WebSocket conn, String message ) {

}

@Override
public void onError( WebSocket conn, Exception ex ) {

}

@Override
public void onStart() {
countServerDownLatch.countDown();
}
};
ws.start();
countServerDownLatch.await();
WebSocketClient clt = new WebSocketClient( new URI( "ws://localhost:" + port ) ) {
@Override
public void onOpen( ServerHandshake handshakedata ) {

}

@Override
public void onMessage( String message ) {

}

@Override
public void onClose( int code, String reason, boolean remote ) {

}

@Override
public void onError( Exception ex ) {

}
};
clt.connectBlocking();
clt.send("test");
if (closeBlocking) {
clt.closeBlocking();
}
ws.stop();
Thread.sleep( 100 );
}

@Test
public void runNoCloseBlockingTestScenario0() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario1() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario2() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario3() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario4() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario5() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario6() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario7() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario8() throws Exception {
runTestScenario(false);
}
@Test
public void runNoCloseBlockingTestScenario9() throws Exception {
runTestScenario(false);
}

@Test
public void runCloseBlockingTestScenario0() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario1() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario2() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario3() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario4() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario5() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario6() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario7() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario8() throws Exception {
runTestScenario(true);
}
@Test
public void runCloseBlockingTestScenario9() throws Exception {
runTestScenario(true);
}

}

Loading