{"id":20180853,"url":"https://github.com/scalecube/socketio","last_synced_at":"2025-08-20T10:33:05.697Z","repository":{"id":38361733,"uuid":"13797726","full_name":"scalecube/socketio","owner":"scalecube","description":"Socket.IO Java Server based on Netty. was created to meet gaming performance requirements. battle tested and in use by Playtech Microservices API Gateway.","archived":false,"fork":false,"pushed_at":"2018-11-08T13:57:20.000Z","size":831,"stargazers_count":185,"open_issues_count":3,"forks_count":49,"subscribers_count":39,"default_branch":"master","last_synced_at":"2024-12-07T18:51:30.048Z","etag":null,"topics":["java","server","socketio"],"latest_commit_sha":null,"homepage":"http://scalecube.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scalecube.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-23T08:43:05.000Z","updated_at":"2024-08-08T06:30:34.000Z","dependencies_parsed_at":"2022-08-23T22:40:42.086Z","dependency_job_id":null,"html_url":"https://github.com/scalecube/socketio","commit_stats":null,"previous_names":["socketio4netty/socketio4netty","servicefabric/socketio"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalecube%2Fsocketio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalecube%2Fsocketio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalecube%2Fsocketio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalecube%2Fsocketio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scalecube","download_url":"https://codeload.github.com/scalecube/socketio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230415318,"owners_count":18222158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","server","socketio"],"created_at":"2024-11-14T02:33:12.138Z","updated_at":"2024-12-19T10:10:29.068Z","avatar_url":"https://github.com/scalecube.png","language":"Java","readme":"# Socket.IO Java Server\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/600c1a00c50348d09c713059a76a348d)](https://www.codacy.com/app/ScaleCube/socketio_2?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=scalecube/socketio\u0026utm_campaign=badger)\n[![Build Status](https://travis-ci.org/scalecube/socketio.svg?branch=master)](https://travis-ci.org/scalecube/socketio)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.scalecube/socketio/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.scalecube/socketio)\n \nScaleCube Socket.IO is a lightweight implementation of [Socket.IO](http://socket.io) Java server based on \n[Netty](http://netty.io) framework. It implements subset of Socket.IO protocol and optimized for high throughput \nand low latency real-time messaging. It is designed to support requirements of most demanding modern applications \nsuch as online gaming, financial trading, social and advertising platforms.\n\nSocket.IO protocol provides WebSocket transport with fallback options to other transports such as XHR-Polling \nin case if client does not support or unable to establish WebSocket connection (e.g. due to proxy or firewall \nrestrictions). It supports reconnection mechanism based on exponential backoff algorithm and heartbeat-based \ndetection of disconnections.\n\nScaleCube Socket.IO is a lightweight embeddable library with minimum dependencies for the Java VM. Major use case\nis to provide an implementation of transport layer for [API Gateway](http://microservices.io/patterns/apigateway.html) \npattern in microservices architecture. Mobile and web clients use Socket.IO transport to communicate with application \nmicroservices.\n\nSupported transport protocols:\n* WebSocket\n* Flash Socket\n* XHR-Polling\n* JSONP-Polling\n\nSupports 0.7+ up to 0.9.16 versions of \n[Socket.IO-client](https://github.com/socketio/socket.io-client/tree/0.9).\n\n## Performance\n\nTested on VM: CentOS, 4vCPU, 2GB RAM, Java 7\n\nClient Sessions:\n- 10,000 long-polling sessions on single node\n- 50,000 WebSocket sessions on single node\n\nTPS:\n- 4,000 requests per second per single channel\n- 80,000 requests per second total\n\n## Getting Started\n\nStart echo Socket.IO server on default port (`8080`) as simple as:\n\n``` java\nSocketIOServer echoServer = SocketIOServer.newInstance();\nechoServer.setListener(new SocketIOAdapter() {\n  public void onMessage(Session session, ByteBuf message) {\n    session.send(message);\n  }\n});\nechoServer.start();\n```\n\nStart Socket.IO server on port `5000` which prints to console all received messages and connected/disconnected events:\n\n``` java\nSocketIOServer logServer = SocketIOServer.newInstance(5000 /*port*/);\nlogServer.setListener(new SocketIOListener() {\n  public void onConnect(Session session) {\n    System.out.println(\"Connected: \" + session);  \n  }\n  \n  public void onMessage(Session session, ByteBuf message) {\n    System.out.println(\"Received: \" + message.toString(CharsetUtil.UTF_8));\n    message.release();\n  }\n  \n  public void onDisconnect(Session session) {\n    System.out.println(\"Disconnected: \" + session);  \n  }\n});\nlogServer.start();\n```\n\nReceived message has type of Netty's [ByteBuffer](https://netty.io/4.0/api/io/netty/buffer/ByteBuf.html). \nSince the popular use case are proxy-like applications it allows to resend received payload without full decoding it. \nIf byte buffer will be sent to another Netty channel it will be released automatically, otherwise it is required \nto manually release buffer.\n\nTo 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)\nor Netty's [SslContext](https://netty.io/4.1/api/io/netty/handler/ssl/SslContext.html) which may be backed by OpenSSL implementation:\n\n``` java\n// Server config\nSSLContext sslContext = ... // your server's SSLContext \nServerConfiguration configWithSsl = ServerConfiguration.builder()\n    .port(443)\n    .sslContext(sslContext)\n    .build();\n    \n// Start server\nSocketIOServer sslServer = SocketIOServer.newInstance(configWithSsl);\nsslServer.setListener(new SocketIOAdapter() { /* listener code */ });\nsslServer.start();\n```\n\nTo play with your Socket.IO server you may use our [demo client](http://scalecube.io/socketio/).   \n\nFor more examples and demo client application, see [Socket.IO Examples](https://github.com/scalecube/socketio-examples). \n\n## Maven \n\nBinaries and dependency information for Maven can be found at \n[http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.scalecube%22%20AND%20a%3A%22socketio%22).\n\nChange history and version numbers at [CHANGES.md](https://github.com/scalecube/socketio/blob/master/CHANGES.md).\n\nMaven dependency: \n\n``` xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.scalecube\u003c/groupId\u003e\n  \u003cartifactId\u003esocketio\u003c/artifactId\u003e\n  \u003cversion\u003ex.y.z\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nAll dependencies are made optional in order to allow change to compatible version used by your project.\nSo following or compatible versions of Netty 4.1.x and slf4j-api 1.7.x modules should be added to your project:\n\n``` xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-buffer\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-common\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-handler\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-codec\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-codec-http\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-transport\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.netty\u003c/groupId\u003e\n  \u003cartifactId\u003enetty-transport-native-epoll\u003c/artifactId\u003e\n  \u003cversion\u003e4.1.6.Final\u003c/version\u003e\n  \u003cclassifier\u003elinux-x86_64\u003c/classifier\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.slf4j\u003c/groupId\u003e\n  \u003cartifactId\u003eslf4j-api\u003c/artifactId\u003e\n  \u003cversion\u003e1.7.22\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Server configuration\n\n- *port*\n  \n  Port on which Socket.IO server will be started. Default value is `8080`.\n\n- *sslContext*\n\n  SSL context which is used to run secure socket. If it's set to `null` server runs without SSL.\n  Default value is `null`.\n\n- *transports*\n  \n  A string with list of allowed transport methods separated by comma.\n  Default value is `\"websocket,flashsocket,xhr-polling,jsonp-polling\"`.\n\n- *heartbeatTimeout*\n  \n  The timeout in seconds for the client when it should send a new heart\n  beat to the server. This value is sent to the client after a successful\n  handshake. The default value is `60`.\n\n- *closeTimeout*\n  \n  The timeout in seconds for the client, when it closes the connection it\n  still X amounts of seconds to do re open of the connection. This value is\n  sent to the client after a successful handshake. Default value is `60`.\n\n- *heartbeatInterval*\n\n  The timeout in seconds for the server, we should receive a heartbeat from\n  the client within this interval. This should be less than the heartbeat\n  timeout. Default value is `25`.\n\n- *eventExecutorEnabled*\n  \n  Flag which defines if listener will be executed, true - different thread, false - io-thread.\n  Default is `true`.\n  \n- *eventExecutorThreadNumber*\n  \n  Event executor thread number, if eventExecutorEnabled flag set to true.\n  Default value is `Runtime.getRuntime().availableProcessors() x 2`.\n\n- *maxWebSocketFrameSize*\n  \n  Maximum allowable web socket frame payload length. Setting this value to your application's requirement may\n  reduce denial of service attacks using long data frames. Default is `65536`.\n  \n- *alwaysSecureWebSocketLocation*\n  \n  Flag which if set to true will always return secure web socket location protocol (\"wss://\")\n  even when connection is established over plain socket. It is used as a workaround related to case\n  when SSL is offloaded to Load Balancer, but it doesn't modify web socket location. By default it\n  is `false`.\n\n- *remoteAddressHeader*\n  \n  The HTTP header name which is used as a session remote address. It is a workaround related to case\n  when Load Balancer modify client address with its address. This header is supposed to be set by Load\n  Balancer. If it is set to `null` then this header is not used. Default value is `null`.\n  \n- *epollEnabled*\n\n  Flag which defines if Linux native [epoll](https://en.wikipedia.org/wiki/Epoll) transport will be used \n  if available. Default is `true`.\n  \n- *httpCompressionEnabled*\n\n  Flag which defines if HTTP compression is enabled. Default is `false`.\n  \n- *websocketCompressionEnabled*\n\n  Flag which defines if websocket compression is enabled. Default is `false`.\n\n## Bugs and Feedback\n\nFor bugs, questions and discussions please use the [GitHub Issues](https://github.com/scalecube/socketio/issues).\n\n## License\n\n[Apache License, Version 2.0](https://github.com/scalecube/socketio/blob/master/LICENSE.txt)\n","funding_links":[],"categories":["网络编程"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalecube%2Fsocketio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscalecube%2Fsocketio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalecube%2Fsocketio/lists"}