Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scalecube/socketio
Socket.IO Java Server based on Netty. was created to meet gaming performance requirements. battle tested and in use by Playtech Microservices API Gateway.
https://github.com/scalecube/socketio
java server socketio
Last synced: 8 days ago
JSON representation
Socket.IO Java Server based on Netty. was created to meet gaming performance requirements. battle tested and in use by Playtech Microservices API Gateway.
- Host: GitHub
- URL: https://github.com/scalecube/socketio
- Owner: scalecube
- License: apache-2.0
- Created: 2013-10-23T08:43:05.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-11-08T13:57:20.000Z (about 6 years ago)
- Last Synced: 2024-12-07T18:51:30.048Z (20 days ago)
- Topics: java, server, socketio
- Language: Java
- Homepage: http://scalecube.io
- Size: 812 KB
- Stars: 185
- Watchers: 39
- Forks: 49
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Socket.IO Java Server
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/600c1a00c50348d09c713059a76a348d)](https://www.codacy.com/app/ScaleCube/socketio_2?utm_source=github.com&utm_medium=referral&utm_content=scalecube/socketio&utm_campaign=badger)
[![Build Status](https://travis-ci.org/scalecube/socketio.svg?branch=master)](https://travis-ci.org/scalecube/socketio)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.scalecube/socketio/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.scalecube/socketio)
ScaleCube Socket.IO is a lightweight implementation of [Socket.IO](http://socket.io) Java server based on
[Netty](http://netty.io) framework. It implements subset of Socket.IO protocol and optimized for high throughput
and low latency real-time messaging. It is designed to support requirements of most demanding modern applications
such as online gaming, financial trading, social and advertising platforms.Socket.IO protocol provides WebSocket transport with fallback options to other transports such as XHR-Polling
in case if client does not support or unable to establish WebSocket connection (e.g. due to proxy or firewall
restrictions). It supports reconnection mechanism based on exponential backoff algorithm and heartbeat-based
detection of disconnections.ScaleCube Socket.IO is a lightweight embeddable library with minimum dependencies for the Java VM. Major use case
is to provide an implementation of transport layer for [API Gateway](http://microservices.io/patterns/apigateway.html)
pattern in microservices architecture. Mobile and web clients use Socket.IO transport to communicate with application
microservices.Supported transport protocols:
* WebSocket
* Flash Socket
* XHR-Polling
* JSONP-PollingSupports 0.7+ up to 0.9.16 versions of
[Socket.IO-client](https://github.com/socketio/socket.io-client/tree/0.9).## Performance
Tested on VM: CentOS, 4vCPU, 2GB RAM, Java 7
Client Sessions:
- 10,000 long-polling sessions on single node
- 50,000 WebSocket sessions on single nodeTPS:
- 4,000 requests per second per single channel
- 80,000 requests per second total## Getting Started
Start echo Socket.IO server on default port (`8080`) as simple as:
``` java
SocketIOServer echoServer = SocketIOServer.newInstance();
echoServer.setListener(new SocketIOAdapter() {
public void onMessage(Session session, ByteBuf message) {
session.send(message);
}
});
echoServer.start();
```Start Socket.IO server on port `5000` which prints to console all received messages and connected/disconnected events:
``` java
SocketIOServer logServer = SocketIOServer.newInstance(5000 /*port*/);
logServer.setListener(new SocketIOListener() {
public void onConnect(Session session) {
System.out.println("Connected: " + session);
}
public void onMessage(Session session, ByteBuf message) {
System.out.println("Received: " + message.toString(CharsetUtil.UTF_8));
message.release();
}
public void onDisconnect(Session session) {
System.out.println("Disconnected: " + session);
}
});
logServer.start();
```Received message has type of Netty's [ByteBuffer](https://netty.io/4.0/api/io/netty/buffer/ByteBuf.html).
Since the popular use case are proxy-like applications it allows to resend received payload without full decoding it.
If byte buffer will be sent to another Netty channel it will be released automatically, otherwise it is required
to manually release buffer.To start Socket.IO server with SSL/TLS support you need to provide in server config either JDK's [SSLContext](https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/SSLContext.html)
or Netty's [SslContext](https://netty.io/4.1/api/io/netty/handler/ssl/SslContext.html) which may be backed by OpenSSL implementation:``` java
// Server config
SSLContext sslContext = ... // your server's SSLContext
ServerConfiguration configWithSsl = ServerConfiguration.builder()
.port(443)
.sslContext(sslContext)
.build();
// Start server
SocketIOServer sslServer = SocketIOServer.newInstance(configWithSsl);
sslServer.setListener(new SocketIOAdapter() { /* listener code */ });
sslServer.start();
```To play with your Socket.IO server you may use our [demo client](http://scalecube.io/socketio/).
For more examples and demo client application, see [Socket.IO Examples](https://github.com/scalecube/socketio-examples).
## Maven
Binaries and dependency information for Maven can be found at
[http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.scalecube%22%20AND%20a%3A%22socketio%22).Change history and version numbers at [CHANGES.md](https://github.com/scalecube/socketio/blob/master/CHANGES.md).
Maven dependency:
``` xml
io.scalecube
socketio
x.y.z```
All dependencies are made optional in order to allow change to compatible version used by your project.
So following or compatible versions of Netty 4.1.x and slf4j-api 1.7.x modules should be added to your project:``` xml
io.netty
netty-buffer
4.1.6.Finalio.netty
netty-common
4.1.6.Finalio.netty
netty-handler
4.1.6.Finalio.netty
netty-codec
4.1.6.Finalio.netty
netty-codec-http
4.1.6.Finalio.netty
netty-transport
4.1.6.Finalio.netty
netty-transport-native-epoll
4.1.6.Final
linux-x86_64org.slf4j
slf4j-api
1.7.22```
## Server configuration
- *port*
Port on which Socket.IO server will be started. Default value is `8080`.- *sslContext*
SSL context which is used to run secure socket. If it's set to `null` server runs without SSL.
Default value is `null`.- *transports*
A string with list of allowed transport methods separated by comma.
Default value is `"websocket,flashsocket,xhr-polling,jsonp-polling"`.- *heartbeatTimeout*
The timeout in seconds for the client when it should send a new heart
beat to the server. This value is sent to the client after a successful
handshake. The default value is `60`.- *closeTimeout*
The timeout in seconds for the client, when it closes the connection it
still X amounts of seconds to do re open of the connection. This value is
sent to the client after a successful handshake. Default value is `60`.- *heartbeatInterval*
The timeout in seconds for the server, we should receive a heartbeat from
the client within this interval. This should be less than the heartbeat
timeout. Default value is `25`.- *eventExecutorEnabled*
Flag which defines if listener will be executed, true - different thread, false - io-thread.
Default is `true`.
- *eventExecutorThreadNumber*
Event executor thread number, if eventExecutorEnabled flag set to true.
Default value is `Runtime.getRuntime().availableProcessors() x 2`.- *maxWebSocketFrameSize*
Maximum allowable web socket frame payload length. Setting this value to your application's requirement may
reduce denial of service attacks using long data frames. Default is `65536`.
- *alwaysSecureWebSocketLocation*
Flag which if set to true will always return secure web socket location protocol ("wss://")
even when connection is established over plain socket. It is used as a workaround related to case
when SSL is offloaded to Load Balancer, but it doesn't modify web socket location. By default it
is `false`.- *remoteAddressHeader*
The HTTP header name which is used as a session remote address. It is a workaround related to case
when Load Balancer modify client address with its address. This header is supposed to be set by Load
Balancer. If it is set to `null` then this header is not used. Default value is `null`.
- *epollEnabled*Flag which defines if Linux native [epoll](https://en.wikipedia.org/wiki/Epoll) transport will be used
if available. Default is `true`.
- *httpCompressionEnabled*Flag which defines if HTTP compression is enabled. Default is `false`.
- *websocketCompressionEnabled*Flag which defines if websocket compression is enabled. Default is `false`.
## Bugs and Feedback
For bugs, questions and discussions please use the [GitHub Issues](https://github.com/scalecube/socketio/issues).
## License
[Apache License, Version 2.0](https://github.com/scalecube/socketio/blob/master/LICENSE.txt)