Skip to content

Commit 75d7f09

Browse files
authored
Merge pull request TooTallNate#622 from marci4/master
Fix for TooTallNate#621
2 parents 27209fd + e91a0ea commit 75d7f09

File tree

7 files changed

+456
-40
lines changed

7 files changed

+456
-40
lines changed

README.markdown

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ Then you can just add the latest version to your build.
4949
compile "org.java-websocket:Java-WebSocket:1.3.6"
5050
```
5151

52-
53-
### Leiningen
54-
55-
``` bash
56-
[org.java-websocket/java-websocket "1.3.6"]
57-
```
58-
5952
Running the Examples
6053
-------------------
6154

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

82-
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
83-
implementation will be used, otherwise it will fall back to a
84-
[Flash-based WebSocket Implementation](http://github.com/gimite/web-socket-js).
85-
75+
In the example folder is also a simple HTML file chat client `chat.html`, which can be opened by any browser.
8676

8777
Writing your own WebSocket Server
8878
---------------------------------
@@ -99,7 +89,7 @@ Writing your own WebSocket Client
9989

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

@@ -129,8 +119,8 @@ Minimum Required JDK
129119

130120
`Java-WebSocket` is known to work with:
131121

132-
* Java 1.5 (aka SE 6)
133-
* Android 1.6 (API 4)
122+
* Java 1.6 and higher
123+
* Android 4.0 and higher
134124

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

build.xml

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
<project default="all">
2-
<target name="all" depends="doc,jar" />
2+
<target name="all" depends="doc,jar" />
33

4-
<target name="compile">
5-
<mkdir dir="build/classes" />
6-
<mkdir dir="build/examples" />
7-
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
8-
destdir="build/classes" target="1.6" source="1.6">
9-
</javac>
10-
<javac includeantruntime="false" srcdir="src/main/example/"
11-
classpath="build/classes" destdir="build/examples" />
12-
</target>
4+
<target name="compile">
5+
<mkdir dir="build/classes" />
6+
<mkdir dir="build/examples" />
7+
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
8+
destdir="build/classes" target="1.6" source="1.6">
9+
</javac>
10+
<javac includeantruntime="false" srcdir="src/main/example/"
11+
classpath="build/classes" destdir="build/examples" />
12+
</target>
1313

14-
<target name="jar" depends="compile">
15-
<mkdir dir="dist"/>
16-
<jar destfile="dist/java_websocket.jar">
17-
<fileset dir="build/classes" includes="**/*.class" />
18-
</jar>
19-
</target>
14+
<target name="jar" depends="compile">
15+
<mkdir dir="dist"/>
16+
<jar destfile="dist/java_websocket.jar">
17+
<fileset dir="build/classes" includes="**/*.class" />
18+
</jar>
19+
</target>
2020

21-
<target name="doc">
22-
<delete dir="doc" />
23-
<javadoc sourcepath="src/main/java" destdir="doc" />
24-
</target>
21+
<target name="compileAutobahn">
22+
<mkdir dir="build/classes" />
23+
<mkdir dir="build/examples" />
24+
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
25+
destdir="build/classes" target="1.6" source="1.6">
26+
</javac>
27+
<javac includeantruntime="false" debug="on" srcdir="src/test/java/org/java_websocket/example"
28+
destdir="build/classes" target="1.6" source="1.6">
29+
</javac>
30+
</target>
2531

26-
<target name="clean">
27-
<delete dir="build" />
28-
<delete dir="dist" />
29-
</target>
32+
<target name="jarAutobahn" depends="compileAutobahn">
33+
<mkdir dir="dist"/>
34+
<jar destfile="dist/autobahnserver.jar">
35+
<fileset dir="build/classes" includes="**/*.class" />
36+
<manifest>
37+
<attribute name="Main-Class" value="org.java_websocket.example.AutobahnServerTest"/>
38+
</manifest>
39+
</jar>
40+
</target>
41+
42+
<target name="doc">
43+
<delete dir="doc" />
44+
<javadoc sourcepath="src/main/java" destdir="doc" />
45+
</target>
46+
47+
<target name="clean">
48+
<delete dir="build" />
49+
<delete dir="dist" />
50+
</target>
3051

3152
</project>

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void decode( ByteBuffer socketBuffer ) {
206206
decodeFrames( socketBuffer );
207207
}
208208
} else {
209-
if( decodeHandshake( socketBuffer ) ) {
209+
if( decodeHandshake( socketBuffer ) && (!isClosing() && !isClosed())) {
210210
assert ( tmpHandshakeBytes.hasRemaining() != socketBuffer.hasRemaining() || !socketBuffer.hasRemaining() ); // the buffers will never have remaining bytes at the same time
211211

212212
if( socketBuffer.hasRemaining() ) {

src/test/java/org/java_websocket/issues/AllIssueTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
@RunWith(Suite.class)
3232
@Suite.SuiteClasses({
33-
org.java_websocket.issues.Issue609Test.class
33+
org.java_websocket.issues.Issue609Test.class,
34+
org.java_websocket.issues.Issue621Test.class,
35+
org.java_websocket.issues.Issue580Test.class
3436
})
3537
/**
3638
* Start all tests for issues
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Copyright (c) 2010-2017 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket.issues;
27+
28+
import org.java_websocket.WebSocket;
29+
import org.java_websocket.client.WebSocketClient;
30+
import org.java_websocket.framing.CloseFrame;
31+
import org.java_websocket.handshake.ClientHandshake;
32+
import org.java_websocket.handshake.ServerHandshake;
33+
import org.java_websocket.server.WebSocketServer;
34+
import org.java_websocket.util.SocketUtil;
35+
import org.java_websocket.util.ThreadCheck;
36+
import org.junit.Rule;
37+
import org.junit.Test;
38+
39+
import java.net.InetSocketAddress;
40+
import java.net.URI;
41+
import java.util.concurrent.CountDownLatch;
42+
43+
public class Issue580Test {
44+
45+
@Rule
46+
public ThreadCheck zombies = new ThreadCheck();
47+
48+
private void runTestScenario(boolean closeBlocking) throws Exception {
49+
final CountDownLatch countServerDownLatch = new CountDownLatch( 1 );
50+
int port = SocketUtil.getAvailablePort();
51+
WebSocketServer ws = new WebSocketServer( new InetSocketAddress( port ) ) {
52+
@Override
53+
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
54+
55+
}
56+
57+
@Override
58+
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
59+
60+
}
61+
62+
@Override
63+
public void onMessage( WebSocket conn, String message ) {
64+
65+
}
66+
67+
@Override
68+
public void onError( WebSocket conn, Exception ex ) {
69+
70+
}
71+
72+
@Override
73+
public void onStart() {
74+
countServerDownLatch.countDown();
75+
}
76+
};
77+
ws.start();
78+
countServerDownLatch.await();
79+
WebSocketClient clt = new WebSocketClient( new URI( "ws://localhost:" + port ) ) {
80+
@Override
81+
public void onOpen( ServerHandshake handshakedata ) {
82+
83+
}
84+
85+
@Override
86+
public void onMessage( String message ) {
87+
88+
}
89+
90+
@Override
91+
public void onClose( int code, String reason, boolean remote ) {
92+
93+
}
94+
95+
@Override
96+
public void onError( Exception ex ) {
97+
98+
}
99+
};
100+
clt.connectBlocking();
101+
clt.send("test");
102+
if (closeBlocking) {
103+
clt.closeBlocking();
104+
}
105+
ws.stop();
106+
Thread.sleep( 100 );
107+
}
108+
109+
@Test
110+
public void runNoCloseBlockingTestScenario0() throws Exception {
111+
runTestScenario(false);
112+
}
113+
@Test
114+
public void runNoCloseBlockingTestScenario1() throws Exception {
115+
runTestScenario(false);
116+
}
117+
@Test
118+
public void runNoCloseBlockingTestScenario2() throws Exception {
119+
runTestScenario(false);
120+
}
121+
@Test
122+
public void runNoCloseBlockingTestScenario3() throws Exception {
123+
runTestScenario(false);
124+
}
125+
@Test
126+
public void runNoCloseBlockingTestScenario4() throws Exception {
127+
runTestScenario(false);
128+
}
129+
@Test
130+
public void runNoCloseBlockingTestScenario5() throws Exception {
131+
runTestScenario(false);
132+
}
133+
@Test
134+
public void runNoCloseBlockingTestScenario6() throws Exception {
135+
runTestScenario(false);
136+
}
137+
@Test
138+
public void runNoCloseBlockingTestScenario7() throws Exception {
139+
runTestScenario(false);
140+
}
141+
@Test
142+
public void runNoCloseBlockingTestScenario8() throws Exception {
143+
runTestScenario(false);
144+
}
145+
@Test
146+
public void runNoCloseBlockingTestScenario9() throws Exception {
147+
runTestScenario(false);
148+
}
149+
150+
@Test
151+
public void runCloseBlockingTestScenario0() throws Exception {
152+
runTestScenario(true);
153+
}
154+
@Test
155+
public void runCloseBlockingTestScenario1() throws Exception {
156+
runTestScenario(true);
157+
}
158+
@Test
159+
public void runCloseBlockingTestScenario2() throws Exception {
160+
runTestScenario(true);
161+
}
162+
@Test
163+
public void runCloseBlockingTestScenario3() throws Exception {
164+
runTestScenario(true);
165+
}
166+
@Test
167+
public void runCloseBlockingTestScenario4() throws Exception {
168+
runTestScenario(true);
169+
}
170+
@Test
171+
public void runCloseBlockingTestScenario5() throws Exception {
172+
runTestScenario(true);
173+
}
174+
@Test
175+
public void runCloseBlockingTestScenario6() throws Exception {
176+
runTestScenario(true);
177+
}
178+
@Test
179+
public void runCloseBlockingTestScenario7() throws Exception {
180+
runTestScenario(true);
181+
}
182+
@Test
183+
public void runCloseBlockingTestScenario8() throws Exception {
184+
runTestScenario(true);
185+
}
186+
@Test
187+
public void runCloseBlockingTestScenario9() throws Exception {
188+
runTestScenario(true);
189+
}
190+
191+
}
192+

0 commit comments

Comments
 (0)