All Projects → hiwepy → Socketio Spring Boot Starter

hiwepy / Socketio Spring Boot Starter

Licence: apache-2.0
Spring Boot Starter For Netty-socketio

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Socketio Spring Boot Starter

E2e Experiment
A demo project with Spring Boot / Angular application and e2e tests
Stars: ✭ 9 (-67.86%)
Mutual labels:  spring-boot
Spring Reactive Sample
Spring 5 Reactive playground
Stars: ✭ 867 (+2996.43%)
Mutual labels:  spring-boot
Cloud Enabled Microservice
Tasks microservice (Spring Boot, MVC, Data, Lombok, Cloud, OAuth2, Config, Eureka, Zuul, Hystrix, Docker)
Stars: ✭ 14 (-50%)
Mutual labels:  spring-boot
Spring Boot Rest Api Example
Implement REST APIs using Spring Boot and Spring Session.
Stars: ✭ 10 (-64.29%)
Mutual labels:  spring-boot
Spring Cloud Examples
Examples of microservice instrastructures
Stars: ✭ 11 (-60.71%)
Mutual labels:  spring-boot
Ii
Интерактивная Ииссиидиология
Stars: ✭ 12 (-57.14%)
Mutual labels:  spring-boot
Newbee Mall Vue App
Vue2 全家桶 + Vant 搭建大型单页面商城项目。新蜂商城前后端分离版本-前端Vue项目源码
Stars: ✭ 836 (+2885.71%)
Mutual labels:  spring-boot
Spring Cloud Book
《使用Spring Cloud与Docker实战微服务》开源书。讨论QQ群:731548893。配套代码:https://github.com/eacdy/spring-cloud-study
Stars: ✭ 886 (+3064.29%)
Mutual labels:  spring-boot
Javaok
必看!java后端,亮剑诛仙。java发展路线技术要点。
Stars: ✭ 867 (+2996.43%)
Mutual labels:  spring-boot
Spring Mvc Thymeleaf Crud
Spring MVC CRUD Application with Thymeleaf, HTML5, CSS3 and Bootstrap
Stars: ✭ 14 (-50%)
Mutual labels:  spring-boot
Hello Sso Jwt Resource
Single Sign On (SSO) Example with JSON Web Token (JWT), Spring Boot
Stars: ✭ 10 (-64.29%)
Mutual labels:  spring-boot
Docker Example
Example Spring Boot Application with Docker
Stars: ✭ 11 (-60.71%)
Mutual labels:  spring-boot
Spring Boot With Activiti Drools Example
Getting started with Activiti and Spring Boot and Drools
Stars: ✭ 13 (-53.57%)
Mutual labels:  spring-boot
Versionmonitor
Monitors different kinds of software projects for new releases
Stars: ✭ 9 (-67.86%)
Mutual labels:  spring-boot
Notes App
Node.js application - simple notes management using Express, Postgres, Objection.js, Docker, Socket.io, Bluebird Promises
Stars: ✭ 14 (-50%)
Mutual labels:  socketio
Springbootunity
rabbitmq、redis、scheduled、socket、mongodb、Swagger2、spring data jpa、Thymeleaf、freemarker etc. (muti module spring boot project) (with spring boot framework,different bussiness scence with different technology。)
Stars: ✭ 845 (+2917.86%)
Mutual labels:  spring-boot
Html Pdf Service
LGPL V3. Java Spring Boot microservice with RESTful webconsole and service endpoints that convert HTML to PDF, optionally styling with CSS and templating with JSON using Flying Saucer, PDF Box and Jackson libraries. Available on Docker Hub.
Stars: ✭ 12 (-57.14%)
Mutual labels:  spring-boot
Microservices Demo
Using Spring Cloud to develop microservices and deploy to Kubernetes
Stars: ✭ 21 (-25%)
Mutual labels:  spring-boot
Netty Websocket Spring Boot Starter
🚀 lightweight high-performance WebSocket framework ( 轻量级、高性能的WebSocket框架)
Stars: ✭ 885 (+3060.71%)
Mutual labels:  spring-boot
Jwebform
Java WebForm Library: HTML Form generation and validation
Stars: ✭ 14 (-50%)
Mutual labels:  spring-boot

socketio-spring-boot-starter

组件简介

基于 netty-socketio 2.x 开源项目实现的Socket项目整合

使用说明

1、Spring Boot 项目添加 Maven 依赖
<dependency>
	<groupId>com.github.hiwepy</groupId>
	<artifactId>socketio-spring-boot-starter</artifactId>
	<version>${project.version}</version>
</dependency>
2、在application.yml文件中增加如下配置
#################################################################################################
### SocketIO 配置:
#################################################################################################
  socketio:
    redis:
      redisson:
        enabled: true
        server: single
        single:
          address: redis://192.168.2.237:6379
          password: redis
          client-name: redis
          connection-minimum-idle-size: 5
          connection-pool-size: 50
      template:
        enabled: false
    # 服务端配置
    server:
      enabled: true
      ## host在本地测试可以设置为localhost或者本机IP,在Linux服务器跑可换成服务器IP
      hostname: 192.168.2.222
      ## netty启动端口
      port: 10065
      ## 添加头部版本信息
      add-version-header: true
      ## Ping消息间隔(毫秒),默认25秒。客户端向服务器发送一条心跳消息间隔
      ping-interval: 25000
      ## Ping消息超时时间(毫秒),默认60秒,这个时间间隔内没有接收到心跳消息就会发送超时事件
      ping-timeout: 60000
      ## 设置最大每帧处理数据的长度,防止他人利用大数据来攻击服务器
      max-frame-payload-length: 1048576
      ## 设置http交互最大内容长度
      max-http-content-length: 1048576
      ## socket连接数大小(如只监听一个端口boss线程组为1即可)
      boss-threads: 1
      transports:
      - polling
      - websocket
      worker-threads: 100
      ## 协议升级超时时间(毫秒),默认10秒。HTTP握手升级为ws协议超时时间
      upgrade-timeout: 15000
      ## socket配置
      socket-config:
        reuse-address: true
        tcp-no-delay: true
        so-linger: 0
      ack-mode: auto
      allow-custom-requests: true
      ## sessionID 通过请求头io来获取
      random-session: false
3、前端示例
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Socketio chat</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.0/socket.io.js"></script>
</head>
<body>
    <h1>Netty-socketio chat demo</h1>
    <br />
    <div id="console" class="well"></div>
    <form class="well form-inline" onsubmit="return false;">
        <input id="from" class="input-xlarge" type="text" placeholder="from. . . " />
        <input id="to" class="input-xlarge" type="text" placeholder="to. . . " />
        <input id="content" class="input-xlarge" type="text" placeholder="content. . . " />
        <button type="button" onClick="sendMessage()" class="btn">Send</button>
        <button type="button" onClick="sendDisconnect()" class="btn">Disconnect</button>
    </form>
</body>
<script type="text/javascript">

    var socket = io.connect('http://192.168.2.222:10065');
    socket.on('connect',function() {
        output('<span class="connect-msg">Client has connected to the server!</span>');
    });
    socket.on('onSocketEvent', function(data) {
        output('<span class="username-msg">' + data.from + "对你说:" + data.content + '</span>');
    });
    socket.on('disconnect',function() {
        output('<span class="disconnect-msg">The client has disconnected! </span>');
    });
    function sendDisconnect() {
        socket.disconnect();
    }
    function sendMessage() {
        var from = $("#from").val();
        var to = $("#to").val();
        var content = $('#content').val();
        socket.emit('onSocketEvent', {
            from : from,
            to : to,
            content : content
        });
    }
    function output(message) {
        var currentTime = "<span class='time' >" + new Date() + "</span>";
        var element = $("<div>" + currentTime + " " + message + "</div>");
        $('#console').prepend(element);
    }
</script>
<style>
body {
    padding: 20px;
}
#console {
    height: 400px;
    overflow: auto;
    border: 1px solid #ccc;
}
.username-msg {
    color: orange;
}
.connect-msg {
    color: green;
}
.disconnect-msg {
    color: red;
}
.send-msg {
    color: #888
}
</style>
</html>
3、如果通过Nginx进行服务负载,需要添加如下配置:
	location ~ /socket.io {   

       	proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_buffering off;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Nginx-Proxy true;

        proxy_connect_timeout 60s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        send_timeout 600s;

        proxy_pass http://122.224.247.131:10065;
    }
4、如果你的项目使用了uni-app进行移动端开发,需要进行接口对接,可参考如下代码进行
var socketTask = uni.connectSocket({
	url: 'wss://{your-domain}/socket.io/?transport=websocket',
	header: {
		'X-Authorization'	: token,
		'io'				: 'test'
	},
	success: (res)=> {
		console.log(res);	
	},
	fail: (res)=> {
		console.log(res);	
	},
	complete: ()=> {
	}
});
uni.onSocketOpen(function (res) {
	console.log('WebSocket连接已打开!');		  
});
uni.onSocketError(function (res) {
	console.log(res,'WebSocket连接打开失败,请检查!');
});
uni.onSocketMessage(function (res) {
	console.log('收到服务器内容:' + res.data);
});
uni.onSocketClose(function (res) {
	console.log(res, 'WebSocket 已关闭!');
});

代码示例

https://github.com/hiwepy/spring-boot-starter-samples/tree/master/spring-boot-sample-socketio

Jeebiz 技术社区

Jeebiz 技术社区 微信公共号小程序,欢迎关注反馈意见和一起交流,关注公众号回复「Jeebiz」拉你入群。

公共号 小程序
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].