├── TODO
├── .gitignore
├── samples
├── jetty
│ ├── src
│ │ ├── assemble
│ │ │ └── distribution.xml
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── codeminders
│ │ │ └── socketio
│ │ │ └── sample
│ │ │ └── jetty
│ │ │ └── ChatServer.java
│ └── pom.xml
├── tomcat
│ ├── src
│ │ ├── assemble
│ │ │ └── distribution.xml
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── codeminders
│ │ │ └── socketio
│ │ │ └── sample
│ │ │ └── tomcat
│ │ │ └── ChatServer.java
│ └── pom.xml
├── pom.xml
└── chat
│ ├── src
│ └── main
│ │ ├── webapp
│ │ ├── META-INF
│ │ │ └── context.xml
│ │ ├── json.js
│ │ ├── WEB-INF
│ │ │ └── web.xml
│ │ └── chat.html
│ │ ├── resources
│ │ └── log4j.xml
│ │ └── java
│ │ └── com
│ │ └── codeminders
│ │ └── socketio
│ │ └── sample
│ │ └── chat
│ │ └── ChatSocketServlet.java
│ └── pom.xml
├── licenses
└── MIT
├── socket-io
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── codeminders
│ │ │ └── socketio
│ │ │ ├── server
│ │ │ ├── ACKListener.java
│ │ │ ├── DisconnectListener.java
│ │ │ ├── UnsupportedTransportException.java
│ │ │ ├── SocketIOProtocolException.java
│ │ │ ├── EventListener.java
│ │ │ ├── transport
│ │ │ │ ├── XHRPollingTransport.java
│ │ │ │ ├── websocket
│ │ │ │ │ ├── WebsocketTransportProvider.java
│ │ │ │ │ ├── WebsocketConfigurator.java
│ │ │ │ │ ├── ServletConfigHolder.java
│ │ │ │ │ ├── SynchronizedWebsocketIO.java
│ │ │ │ │ ├── WebsocketIOServlet.java
│ │ │ │ │ ├── WebsocketIO.java
│ │ │ │ │ ├── WebsocketTransport.java
│ │ │ │ │ └── WebsocketTransportConnection.java
│ │ │ │ ├── AbstractTransportProvider.java
│ │ │ │ ├── AbstractTransport.java
│ │ │ │ ├── JSONPPollingTransport.java
│ │ │ │ ├── AbstractHttpTransport.java
│ │ │ │ ├── AbstractTransportConnection.java
│ │ │ │ └── XHRTransportConnection.java
│ │ │ ├── ConnectionListener.java
│ │ │ ├── SocketIOClosedException.java
│ │ │ ├── ConnectionException.java
│ │ │ ├── Outbound.java
│ │ │ ├── TransportType.java
│ │ │ ├── Config.java
│ │ │ ├── TransportProvider.java
│ │ │ ├── Transport.java
│ │ │ ├── Room.java
│ │ │ ├── TransportConnection.java
│ │ │ ├── ServletBasedConfig.java
│ │ │ ├── Namespace.java
│ │ │ ├── SocketIOManager.java
│ │ │ ├── Socket.java
│ │ │ └── SocketIOServlet.java
│ │ │ ├── common
│ │ │ ├── SocketIOException.java
│ │ │ ├── ConnectionState.java
│ │ │ └── DisconnectReason.java
│ │ │ └── protocol
│ │ │ ├── BinaryPacket.java
│ │ │ ├── ACKPacket.java
│ │ │ ├── EventPacket.java
│ │ │ ├── BinaryACKPacket.java
│ │ │ ├── SocketIOPacket.java
│ │ │ ├── BinaryEventPacket.java
│ │ │ ├── EngineIOPacket.java
│ │ │ └── EngineIOProtocol.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── codeminders
│ │ └── socketio
│ │ └── protocol
│ │ └── EngineIOProtocolTest.java
└── pom.xml
├── README.md
└── pom.xml
/TODO:
--------------------------------------------------------------------------------
1 | * handle b64 flag
2 | * JSONP polling transport (not sure how to test it)
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 | *.cert
3 | *.crt
4 | *.key
5 | *.orig
6 | *.iml
7 | *.ipr
8 | *.iws
9 | *.swp
10 | bin
11 | build
12 | dist
13 | .git
14 | *~
15 | .DS_Store
16 | .idea
17 | .settings
18 | .project
19 | .classpath
20 | war
21 | build.properties
22 | target
23 | com.codeminders.socketio.sample.gwtchat.GWTChat
24 | samples/chat-gwt/src/main/gwt-unitCache/
--------------------------------------------------------------------------------
/samples/jetty/src/assemble/distribution.xml:
--------------------------------------------------------------------------------
1 |
4 | standalone
5 |
6 | jar
7 |
8 |
9 |
10 |
11 | true
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/tomcat/src/assemble/distribution.xml:
--------------------------------------------------------------------------------
1 |
4 | standalone
5 |
6 | jar
7 |
8 |
9 |
10 |
11 | true
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 | com.codeminders.socketio
9 | socketio-parent
10 | 1.0.10
11 |
12 |
13 | socketio-sample
14 | pom
15 |
16 | Socket.IO Samples
17 | Socket.IO Java Samples
18 |
19 |
20 | chat
21 | jetty
22 | tomcat
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/licenses/MIT:
--------------------------------------------------------------------------------
1 | The MIT License
2 | Copyright (c) ${year} ${owner}
3 |
4 | Contributors: ${contributors}
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/samples/chat/src/main/webapp/META-INF/context.xml:
--------------------------------------------------------------------------------
1 |
2 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/samples/chat/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 | com.codeminders.socketio
9 | socketio-sample
10 | 1.0.10
11 |
12 |
13 | socketio-sample-chat
14 | war
15 |
16 | Socket.IO Sample Chat
17 | ${project.name}
18 |
19 |
20 |
21 | com.codeminders.socketio
22 | socket-io
23 | 1.0.10
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.apache.maven.plugins
31 | maven-war-plugin
32 | 2.1.1
33 |
34 | true
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/ACKListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | /**
26 | * @author Alexander Sova (bird@codeminders.com)
27 | */
28 | public interface ACKListener
29 | {
30 | void onACK(Object[] args);
31 | }
32 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/DisconnectListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | import com.codeminders.socketio.common.DisconnectReason;
26 |
27 | /**
28 | * @author Alexander Sova (bird@codeminders.com)
29 | */
30 | public interface DisconnectListener
31 | {
32 | void onDisconnect(Socket socket, DisconnectReason reason, String errorMessage);
33 | }
34 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/UnsupportedTransportException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | /**
26 | * @author Alexander Sova (bird@codeminders.com)
27 | */
28 | public class UnsupportedTransportException extends Exception {
29 |
30 | public UnsupportedTransportException(String name) {
31 | super("Unsupported transport " + name);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/SocketIOProtocolException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | import com.codeminders.socketio.common.SocketIOException;
26 |
27 | /**
28 | * @author Alexander Sova (bird@codeminders.com)
29 | */
30 | public class SocketIOProtocolException extends SocketIOException
31 | {
32 |
33 | public SocketIOProtocolException(String message)
34 | {
35 | super(message);
36 | }
37 |
38 | public SocketIOProtocolException(String message, Throwable cause)
39 | {
40 | super(message, cause);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/common/SocketIOException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2010 Tad Glines
4 | *
5 | * Contributors: Ovea.com, Mycila.com
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | */
25 | package com.codeminders.socketio.common;
26 |
27 | import java.io.IOException;
28 |
29 | public class SocketIOException extends IOException {
30 | private static final long serialVersionUID = 1L;
31 |
32 | public SocketIOException() {
33 | super();
34 | }
35 |
36 | public SocketIOException(String message) {
37 | super(message);
38 | }
39 |
40 | public SocketIOException(Throwable cause) {
41 | super(cause);
42 | }
43 |
44 | public SocketIOException(String message, Throwable cause) { super(message, cause); }
45 | }
46 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/EventListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | /**
26 | * @author Alexander Sova (bird@codeminders.com)
27 | */
28 | public interface EventListener
29 | {
30 | /**
31 | * Called upon incoming event
32 | *
33 | * @param ackRequested true if client requested an acknowledgement
34 | * @param name event name
35 | * @param args event arguments
36 | * @return Object to send back to the caller as an acknowledgement, null if no ack to be sent
37 | */
38 | Object onEvent(String name, Object[] args, boolean ackRequested);
39 | }
40 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/XHRPollingTransport.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2010 Tad Glines
4 | *
5 | * Contributors: Ovea.com, Mycila.com
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | */
25 | package com.codeminders.socketio.server.transport;
26 |
27 | import com.codeminders.socketio.server.TransportConnection;
28 | import com.codeminders.socketio.server.TransportType;
29 |
30 | public class XHRPollingTransport extends AbstractHttpTransport
31 | {
32 | @Override
33 | public TransportType getType()
34 | {
35 | return TransportType.XHR_POLLING;
36 | }
37 |
38 | @Override
39 | public TransportConnection createConnection()
40 | {
41 | return new XHRTransportConnection(this);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/websocket/WebsocketTransportProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server.transport.websocket;
24 |
25 | import com.codeminders.socketio.server.Transport;
26 | import com.codeminders.socketio.server.transport.AbstractTransportProvider;
27 |
28 | /**
29 | * @author Alexander Sova (bird@codeminders.com)
30 | */
31 | public class WebsocketTransportProvider extends AbstractTransportProvider
32 | {
33 | static final Transport websocket = new WebsocketTransport();
34 |
35 | @Override
36 | protected Transport createWebSocketTransport()
37 | {
38 | return websocket;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/ConnectionListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | /**
26 | * @author Alexander Sova (bird@codeminders.com)
27 | */
28 | public interface ConnectionListener
29 | {
30 | /**
31 | * Callback to be called on new connection
32 | *
33 | * @param socket new socket
34 | * @throws ConnectionException thrown if caller want to fail the connection
35 | * for some reason (e.g. authentication error).
36 | * The error message will be sent to the client
37 | */
38 | void onConnect(Socket socket) throws ConnectionException;
39 | }
40 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/SocketIOClosedException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2010 Tad Glines
4 | *
5 | * Contributors: Ovea.com, Mycila.com
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | */
25 | package com.codeminders.socketio.server;
26 |
27 | import com.codeminders.socketio.common.SocketIOException;
28 |
29 | public class SocketIOClosedException extends SocketIOException {
30 | private static final long serialVersionUID = 1L;
31 |
32 | public SocketIOClosedException() {
33 |
34 | }
35 |
36 | public SocketIOClosedException(String message) {
37 | super(message);
38 | }
39 |
40 | public SocketIOClosedException(String message, Throwable cause) {
41 | super(message, cause);
42 | }
43 |
44 | public SocketIOClosedException(Throwable cause) {
45 | super(cause);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/chat/src/main/webapp/json.js:
--------------------------------------------------------------------------------
1 | if(!this.JSON){JSON=function(){function f(n){return n<10?'0'+n:n;}
2 | Date.prototype.toJSON=function(){return this.getUTCFullYear()+'-'+
3 | f(this.getUTCMonth()+1)+'-'+
4 | f(this.getUTCDate())+'T'+
5 | f(this.getUTCHours())+':'+
6 | f(this.getUTCMinutes())+':'+
7 | f(this.getUTCSeconds())+'Z';};var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};function stringify(value,whitelist){var a,i,k,l,r=/["\\\x00-\x1f\x7f-\x9f]/g,v;switch(typeof value){case'string':return r.test(value)?'"'+value.replace(r,function(a){var c=m[a];if(c){return c;}
8 | c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+
9 | (c%16).toString(16);})+'"':'"'+value+'"';case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
10 | if(typeof value.toJSON==='function'){return stringify(value.toJSON());}
11 | a=[];if(typeof value.length==='number'&&!(value.propertyIsEnumerable('length'))){l=value.length;for(i=0;i
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | /**
26 | * @author Alexander Sova (bird@codeminders.com)
27 | */
28 | public class ConnectionException extends Exception
29 | {
30 | private Object args;
31 |
32 | public Object getArgs()
33 | {
34 | return args;
35 | }
36 |
37 | public ConnectionException(String message, Throwable cause, Object args)
38 | {
39 | super(message, cause);
40 | this.args = args;
41 | }
42 |
43 | public ConnectionException(Throwable cause, Object args)
44 | {
45 | super(cause);
46 | this.args = args;
47 | }
48 |
49 | public ConnectionException(Object args)
50 | {
51 | this.args = args;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/websocket/WebsocketConfigurator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server.transport.websocket;
24 |
25 | import javax.websocket.HandshakeResponse;
26 | import javax.websocket.server.HandshakeRequest;
27 | import javax.websocket.server.ServerEndpointConfig;
28 |
29 | /**
30 | * Adds handshake request information to user properties
31 | */
32 | public class WebsocketConfigurator extends ServerEndpointConfig.Configurator
33 | {
34 | @Override
35 | public void modifyHandshake(ServerEndpointConfig config,
36 | HandshakeRequest request,
37 | HandshakeResponse response)
38 | {
39 | config.getUserProperties().put(HandshakeRequest.class.getName(), request);
40 | }
41 | }
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/Outbound.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server;
24 |
25 | import com.codeminders.socketio.common.SocketIOException;
26 |
27 | public interface Outbound
28 | {
29 | /**
30 | * Emits an event to the socket identified by the string name.
31 | *
32 | * @param name event name
33 | * @param args list of arguments. Arguments can contain any type of field that can result of JSON decoding,
34 | * including objects and arrays of arbitrary size. If last argument is {@code ACKListener}
35 | * then this listener to be called upon ACK arriving
36 | * @throws SocketIOException if IO or protocol error happens
37 | */
38 |
39 | void emit(String name, Object... args) throws SocketIOException;
40 | }
41 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/websocket/ServletConfigHolder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server.transport.websocket;
24 |
25 | import javax.servlet.ServletConfig;
26 |
27 | /**
28 | * @author Alex Saveliev (lyolik@codeminders.com)
29 | */
30 | public final class ServletConfigHolder
31 | {
32 | private ServletConfig config;
33 |
34 | private static ServletConfigHolder instance = new ServletConfigHolder();
35 |
36 | private ServletConfigHolder() {
37 | }
38 |
39 | public static ServletConfigHolder getInstance() {
40 | return instance;
41 | }
42 |
43 | public void setConfig(ServletConfig config) {
44 | this.config = config;
45 | }
46 |
47 | public ServletConfig getConfig() {
48 | return this.config;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/protocol/BinaryPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.protocol;
24 |
25 | import java.io.InputStream;
26 | import java.util.Collection;
27 |
28 | /**
29 | * @author Alexander Sova (bird@codeminders.com)
30 | */
31 | public interface BinaryPacket
32 | {
33 | Collection getAttachments();
34 |
35 | /**
36 | * @return true when all expected attachment arrived, false otherwise
37 | */
38 | boolean isComplete();
39 |
40 | /**
41 | * This method to be called when new attachement arrives to the socket
42 | *
43 | * @param attachment new attachment
44 | */
45 | void addAttachment(InputStream attachment);
46 |
47 | SocketIOPacket.Type getType();
48 |
49 | Object[] getArgs();
50 |
51 | void setArgs(Object[] args);
52 | }
53 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/websocket/SynchronizedWebsocketIO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2018 Alex Saveliev (lyolik@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server.transport.websocket;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | * @author Alex Saveliev (lyolik@codeminders.com)
29 | */
30 | public class SynchronizedWebsocketIO extends WebsocketIO {
31 |
32 | public SynchronizedWebsocketIO(javax.websocket.Session remoteEndpoint) {
33 | super(remoteEndpoint);
34 | }
35 |
36 | public synchronized void sendString(String data) throws IOException {
37 | super.sendString(data);
38 | }
39 |
40 | public synchronized void sendBinary(byte[] data) throws IOException {
41 | super.sendBinary(data);
42 | }
43 |
44 | public void disconnect() throws IOException {
45 | remoteEndpoint.close();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/chat/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
28 |
31 |
32 |
33 | ChatSocketServlet
34 | com.codeminders.socketio.sample.chat.ChatSocketServlet
35 |
36 |
37 |
38 | ChatSocketServlet
39 | /socket.io/*
40 |
41 |
42 |
43 | chat.html
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/protocol/ACKPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.protocol;
24 |
25 | import com.codeminders.socketio.server.SocketIOProtocolException;
26 |
27 | /**
28 | * @author Alexander Sova (bird@codeminders.com)
29 | */
30 | public abstract class ACKPacket extends SocketIOPacket
31 | {
32 | private Object[] args;
33 |
34 | public ACKPacket(Type type, int id, String ns, Object[] args)
35 | {
36 | super(type, id, ns);
37 | this.args = args;
38 | }
39 |
40 | @Override
41 | protected String encodeArgs() throws SocketIOProtocolException
42 | {
43 | return SocketIOProtocol.toJSON(args);
44 | }
45 |
46 | public Object[] getArgs()
47 | {
48 | return args;
49 | }
50 |
51 | public void setArgs(Object[] args)
52 | {
53 | this.args = args;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/TransportType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2010 Tad Glines
4 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
5 | *
6 | * Contributors: Ovea.com, Mycila.com
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy
9 | * of this software and associated documentation files (the "Software"), to deal
10 | * in the Software without restriction, including without limitation the rights
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the Software is
13 | * furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | * THE SOFTWARE.
25 | */
26 | package com.codeminders.socketio.server;
27 |
28 | public enum TransportType
29 | {
30 |
31 | WEB_SOCKET("websocket"),
32 | FLASH_SOCKET("flashsocket"),
33 | JSONP_POLLING("jsonp-polling"),
34 | XHR_POLLING("xhr-polling"),
35 | UNKNOWN("");
36 |
37 | private final String name;
38 |
39 | TransportType(String name)
40 | {
41 | this.name = name;
42 | }
43 |
44 | @Override
45 | public String toString()
46 | {
47 | return name;
48 | }
49 |
50 | public static TransportType from(String name)
51 | {
52 | for (TransportType type : values())
53 | {
54 | if (type.name.equals(name))
55 | return type;
56 | }
57 | return UNKNOWN;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/websocket/WebsocketIOServlet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server.transport.websocket;
24 |
25 | import com.codeminders.socketio.server.SocketIOServlet;
26 | import com.codeminders.socketio.server.TransportProvider;
27 |
28 | import javax.servlet.ServletConfig;
29 | import javax.servlet.ServletException;
30 |
31 | /**
32 | * @author Alexander Sova (bird@codeminders.com)
33 | */
34 | public abstract class WebsocketIOServlet extends SocketIOServlet
35 | {
36 | @Override
37 | public void init(ServletConfig config) throws ServletException
38 | {
39 | super.init(config);
40 | ServletConfigHolder.getInstance().setConfig(config);
41 | TransportProvider transportProvider = new WebsocketTransportProvider();
42 | transportProvider.init(config, getServletContext());
43 | setTransportProvider(transportProvider);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/socket-io/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 |
8 |
9 | org.apache.maven.plugins
10 | maven-compiler-plugin
11 |
12 | 1.7
13 | 1.7
14 |
15 |
16 |
17 |
18 |
19 |
20 | com.codeminders.socketio
21 | socketio-parent
22 | 1.0.10
23 |
24 |
25 | socket-io
26 | jar
27 |
28 | Socket.IO Java
29 | Socket.IO server classes
30 |
31 |
32 |
33 | com.fasterxml.jackson.core
34 | jackson-core
35 | 2.9.1
36 |
37 |
38 | com.fasterxml.jackson.core
39 | jackson-databind
40 | 2.9.1
41 |
42 |
43 | javax.websocket
44 | javax.websocket-api
45 | 1.1
46 | provided
47 |
48 |
49 | junit
50 | junit
51 | 4.10
52 | test
53 |
54 |
55 | org.assertj
56 | assertj-core
57 | 3.10.0
58 | test
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/transport/websocket/WebsocketIO.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2018 Alex Saveliev (lyolik@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.server.transport.websocket;
24 |
25 | import java.io.IOException;
26 | import java.nio.ByteBuffer;
27 |
28 | /**
29 | * @author Alex Saveliev (lyolik@codeminders.com)
30 | */
31 | public class WebsocketIO {
32 |
33 | protected javax.websocket.Session remoteEndpoint;
34 |
35 | public WebsocketIO(javax.websocket.Session remoteEndpoint) {
36 | this.remoteEndpoint = remoteEndpoint;
37 | }
38 |
39 | public void sendString(String data) throws IOException {
40 | remoteEndpoint.getBasicRemote().sendText(data);
41 | }
42 |
43 | //TODO: implement streaming. right now it is all in memory.
44 | //TODO: read and send in chunks using sendPartialBytes()
45 | public void sendBinary(byte[] data) throws IOException {
46 | remoteEndpoint.getBasicRemote().sendBinary(ByteBuffer.wrap(data));
47 | }
48 |
49 | public void disconnect() throws IOException {
50 | remoteEndpoint.close();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/server/Config.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2010 Tad Glines
4 | *
5 | * Contributors: Ovea.com, Mycila.com
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | */
25 | package com.codeminders.socketio.server;
26 |
27 | /**
28 | * @author Mathieu Carbou
29 | */
30 | public interface Config
31 | {
32 | String MAX_TEXT_MESSAGE_SIZE = "maxTextMessageSize";
33 | String PING_INTERVAL = "pingInterval";
34 | String TIMEOUT = "timeout";
35 |
36 | String BUFFER_SIZE = "bufferSize";
37 | String MAX_IDLE = "maxIdleTime";
38 |
39 | int DEFAULT_BUFFER_SIZE = 8192;
40 | int DEFAULT_MAX_IDLE = 300 * 1000;
41 |
42 | int DEFAULT_PING_INTERVAL = 25 * 1000; // 25s
43 | int DEFAULT_PING_TIMEOUT = 60 * 1000; // 60s
44 |
45 | long getPingInterval(long def);
46 |
47 | long getTimeout(long def);
48 |
49 | int getBufferSize();
50 |
51 | int getMaxIdle();
52 |
53 | String getString(String key);
54 |
55 | String getString(String key, String def);
56 |
57 | int getInt(String key, int def);
58 |
59 | long getLong(String key, long def);
60 |
61 | boolean getBoolean(String key, boolean def);
62 |
63 | String getNamespace();
64 | }
65 |
--------------------------------------------------------------------------------
/socket-io/src/test/java/com/codeminders/socketio/protocol/EngineIOProtocolTest.java:
--------------------------------------------------------------------------------
1 | package com.codeminders.socketio.protocol;
2 |
3 | import com.codeminders.socketio.server.SocketIOProtocolException;
4 | import org.junit.Test;
5 |
6 | import java.io.ByteArrayInputStream;
7 | import java.io.ByteArrayOutputStream;
8 | import java.io.IOException;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import static org.assertj.core.api.Assertions.assertThat;
13 |
14 | public class EngineIOProtocolTest {
15 | @Test
16 | public void decodeMultiPayload()
17 | throws SocketIOProtocolException, StringIndexOutOfBoundsException
18 | {
19 | String payload = "10:40/stream,1:227:42/stream,[\"SET_STREAM_ID\"]1:1";
20 | List expected = new ArrayList<>();
21 | expected.add(new EngineIOPacket(EngineIOPacket.Type.MESSAGE, "0/stream,"));
22 | expected.add(new EngineIOPacket(EngineIOPacket.Type.PING, ""));
23 | expected.add(new EngineIOPacket(EngineIOPacket.Type.MESSAGE, "2/stream,[\"SET_STREAM_ID\"]"));
24 | expected.add(new EngineIOPacket(EngineIOPacket.Type.CLOSE, ""));
25 |
26 | List result = EngineIOProtocol.decodePayload(payload);
27 | assertThat(result).isEqualTo(expected);
28 | }
29 |
30 | @Test
31 | public void decodeSimplePayload()
32 | throws SocketIOProtocolException
33 | {
34 | String payload = "10:40/stream,";
35 | List expected = new ArrayList<>();
36 | expected.add(new EngineIOPacket(EngineIOPacket.Type.MESSAGE, "0/stream,"));
37 |
38 | List result = EngineIOProtocol.decodePayload(payload);
39 | assertThat(result).isEqualTo(expected);
40 | }
41 |
42 |
43 | @Test
44 | public void binaryEncode_unicodeStrings()
45 | throws IOException
46 | {
47 | final EngineIOPacket packet = new EngineIOPacket(EngineIOPacket.Type.MESSAGE, "Привет!");
48 |
49 | final ByteArrayOutputStream baos = new ByteArrayOutputStream();
50 | EngineIOProtocol.binaryEncode(packet, baos);
51 |
52 | List result = EngineIOProtocol.binaryDecodePayload(new ByteArrayInputStream(baos.toByteArray()));
53 | assertThat(result).hasSize(1);
54 | assertThat(result.get(0)).isEqualTo(packet);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Java backend for `Socket.IO` library (http://socket.io/)
2 |
3 | Supports `Socket.IO` clients version 1.0+
4 | Requires JSR 356-compatible server (tested with Jetty 9 and Tomcat 8)
5 |
6 | Right now only websocket and XHR polling transports are implemented.
7 |
8 | Based on https://github.com/tadglines/Socket.IO-Java
9 |
10 | License: MIT
11 |
12 | ## Websocket endpoint initialization in Jetty
13 |
14 | Default websocket endpoint configuration assumes it's located in the root context and accessible via `/socket.io/` path.
15 |
16 | When `Socket.IO` backend is integrated into webapp managed by Jetty there is no need to perform additional configuration because Jetty scans for `@ServerEndpoint` annotation and initializes websocket endpoint automatically.
17 |
18 | When Jetty server is embedded into your application, websocket endpoint is located in the root context ("/") and expected to be accessible via `/socket.io/` path (default configuration), then in order to initialize endpoint you should add the following code
19 |
20 | ```java
21 | WebSocketServerContainerInitializer.
22 | configureContext(context).
23 | addEndpoint(WebsocketTransportConnection.class);
24 |
25 | ```
26 |
27 | When Jetty server is embedded into your application, but websocket endpoint is either located not in the root context ("/") or expected to be accessible via path other than `/socket.io/`, then in order to initialize endpoint you should add the following code
28 |
29 | ```java
30 | ServerContainer serverContainer = WebSocketServerContainerInitializer.
31 | configureContext(context);
32 | serverContainer.
33 | addEndpoint(new AnnotatedServerEndpointConfig(serverContainer,
34 | WebsocketTransportConnection.class,
35 | WebsocketTransportConnection.class.getAnnotation(ServerEndpoint.class),
36 | null) {
37 | @Override
38 | public String getPath() {
39 | return "/"; // context-relative path, "/bar" for context "/foo" and path "/foo/bar"
40 | }
41 | });
42 | ```
43 | See example in [com.codeminders.socketio.sample.jetty.ChatServer](https://github.com/codeminders/socket.io-server-java/blob/master/samples/jetty/src/main/java/com/codeminders/socketio/sample/jetty/ChatServer.java)
44 |
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/common/DisconnectReason.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2010 Tad Glines
4 | *
5 | * Contributors: Ovea.com, Mycila.com
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | */
25 | package com.codeminders.socketio.common;
26 |
27 | public enum DisconnectReason {
28 | UNKNOWN(-1),
29 | CONNECT_FAILED(1), // A connection attempt failed.
30 | DISCONNECT(2), // Disconnect was called explicitly.
31 | TIMEOUT(3), // A timeout occurred.
32 | CLOSE_FAILED(4), // The connection dropped before an orderly close could complete.
33 | ERROR(5), // A GET or POST returned an error, or an internal error occurred.
34 | CLOSED_REMOTELY(6), // Remote end point initiated a close.
35 | CLIENT_GONE(7), // Remote end point gone away (browser closed or navigated away)
36 | CLOSED(8); // Locally initiated close succeeded.
37 |
38 | private int value;
39 |
40 | DisconnectReason(int v) { this.value = v; }
41 |
42 | public int value() { return value; }
43 |
44 | public static DisconnectReason fromInt(int val) {
45 | switch (val) {
46 | case 1:
47 | return CONNECT_FAILED;
48 | case 2:
49 | return DISCONNECT;
50 | case 3:
51 | return TIMEOUT;
52 | case 4:
53 | return CLOSE_FAILED;
54 | case 5:
55 | return ERROR;
56 | case 6:
57 | return CLOSED_REMOTELY;
58 | case 7:
59 | return CLOSED;
60 | default:
61 | return UNKNOWN;
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/socket-io/src/main/java/com/codeminders/socketio/protocol/EventPacket.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | * Copyright (c) 2015 Alexander Sova (bird@codeminders.com)
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | */
23 | package com.codeminders.socketio.protocol;
24 |
25 | import com.codeminders.socketio.server.SocketIOProtocolException;
26 |
27 | import java.util.ArrayList;
28 | import java.util.Arrays;
29 |
30 | /**
31 | * @author Alexander Sova (bird@codeminders.com)
32 | */
33 | public abstract class EventPacket extends SocketIOPacket
34 | {
35 | private String name;
36 | private Object[] args;
37 |
38 | protected EventPacket(Type type, int id, String ns, String name, Object[] args)
39 | {
40 | super(type, id, ns);
41 | this.name = name;
42 | this.args = args;
43 | }
44 |
45 | public String getName()
46 | {
47 | return name;
48 | }
49 |
50 | public Object[] getArgs()
51 | {
52 | return args;
53 | }
54 |
55 | public void setArgs(Object[] args)
56 | {
57 | this.args = args;
58 | }
59 |
60 | @Override
61 | protected String encodeArgs() throws SocketIOProtocolException
62 | {
63 | // adding name of the event as a first argument
64 | ArrayList