Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 47 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,77 @@
# InChat(当前版本1.6.0)
# tcp-wechat

> 当前主要更新分支,master将会再所有分支开放一定阶段后整改为maven包,提供给大家使用
## 项目介绍

## 分支介绍 im-api
针对小程序与单片机硬件执行Iot物联网通讯(TCP/IP)的一套完整Demo。

腾讯IM(云通信)后端模仿项目,均以API形式对接,如果有前端想要对接的可以运行本分支,本分支预计终版为一个单服务并发30万用户的IM后台项目
## 项目配置

## 分支介绍 paho-mqtt
> 以下说明针对 tag V0.9.1

基于小程序端或移动web端的paho.js与[java MQTT 客户端模拟](https://github.com/eclipse/paho.mqtt.java)的消息订阅与通信,小程序Iot的Demo,目前支持ws格式
> application.xml

## 分支介绍 tcp-wechat
配置tcp端口:8092

基于小程序端与单片机等硬件的TCP/IP的主要通信,Iot中心作为中转,本demo将完全实现具体功能,详情请看分支主页
> com.myself.nettychat.tcptest.TCPTestClient

## 简介
配置连接IP与端口,修改代码中的参数

***(InChat)Iot Netty Chat***
## 启动流程

仿微信聊天应用,一步一步更新,基于SpringBoot-WebSocket通用框架,结合Netty进行聊天社交,并记录聊天日志,
异步存储,前端暂用SUI Mobile,添加实现TCP/IP后端通信端口(MQTT协议、可实时与单片机等TCP硬件通信)、加入图片处理流,
聊天实现文字与图片发送功能、API调用Netty长链接执行发送消息(在线数、用户列表)
1、启动项目,tcp监听成功

## 基本架构图(1.5.2版)
2、运行com.myself.nettychat.tcptest.TCPTestClient (记得先改ip或端口,如果你有修改的话)

![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/ggg1.png)
3、运行PostMan,请求下方的API 进行通信测试

## 功能
## Demo场景

>实时聊天
>异步CRUD处理消息日志
>获取聊天历史
>用户登录、记录登录用户聊天历史
>防止二次登录
>SUI Mobile仿微信样式
>TCP/IP软硬件通信(8092)
>MQTT协议下的Iot物联网通信(8094)
>图片发送聊天功能
>API调用Netty长链接执行发送消息(在线用户数、用户列表)
>下版(1.7.0):好友功能等
小程序端选购售货机中的商品,点击购买(小程序API向Iot中心发送对应商品的开锁信息),Iot中心中转开锁信息给单片机,单片机接收信息打开对应的锁。

## 版本迭代介绍
通信机制:帧头+ID+数据类型+24把锁状态+crc校验+帧尾(可以按照需求进行定制)

* 1.0.0版本
> com.myself.nettychat.config.TCPServerHandler (通信接收的处理类)

用户登录,聊天历史,随机用户名,异步数据写入:https://segmentfault.com/a/1190000016615063

* 1.2.0版本
## API(小程序调用接口)

修复聊天记录功能,实现重复信息录入,完善前端页面,回车监听等:https://segmentfault.com/a/1190000016637814
> http://localhost:8080/susu/back/get_channel_size GET

* 1.3.0版本

用户注册登录功能,系统聊天绑定用户,禁止二次登录等,前端页面大改

* 1.4.1版本

本人主导SUI Mobile构建仿微信样式页面版,使用时开F12手机界面

* 1.5.2版本

TCP/IP软硬件通信-单片机等应用的TCP通信,Netty处理二进制图片发送聊天功能

* 1.5.8版本

MQTT协议软硬件通信等,Iot物联网

* 1.6.0版本

API调用Netty长链接执行发送消息(在线数、用户列表):https://segmentfault.com/a/1190000016603392


## 配置

>application.yml 数据库配置、Netty参数配置

>TCP需先去com.myself.nettychat.tcptest包下执行CRC16myself获取发送数据,

>再执行TCPTestClient发送数据,请勿随意更改发送格式(通信协议来的)

>http://localhost:8080/susu/admin/loginsui 启动访问路径

>mqtt协议测试在mqttclient包下

>http://localhost:8080/susu/swagger-ui.html 查看API文档

## 效果图

![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(5).png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(3).png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(4).png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(2).png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(1).png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/9.png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png)
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png)

## 预留BUG
请求Iot中心,获取当前连接存活状态下的链接实例

```
io.netty.handler.codec.CorruptedFrameException: Max frame length of 65536 has been exceeded.
图片过大,需要在前端做图片上传压缩

Uncaught TypeError: msg.substring is not a function at WebSocket.socket.onmessage (newChat.js:38)
前端代码的一点问题,不影响项目正常运行

java.io.IOException: 远程主机强迫关闭了一个现有的连接。
TCP客户端连接主动关闭,不影响,良性报错
{
"code": 200,
"msg": "成功",
"data": 1
}
```

## 下载地址

下载地址:https://github.com/UncleCatMySelf/SBToNettyChat/releases
> http://localhost:8080/susu/back/get_channel_id_list GET

## 交流与提问
请求Iot中心,当前存活状态下的链接Id列表

提问与Bug上报:https://github.com/UncleCatMySelf/SBToNettyChat/issues
```
{
"code": 200,
"msg": "成功",
"data": [
"F5690137563CC8"
]
}
```

QQ群:628793702(仅供交流,不提供问题解答)
> http://localhost:8080/susu/back/send_to_channel POST

## 关于作者
参数
* channelId //第二个API获取到的链接Id
* lock //将要打开的第几把锁 1-24(看单片机接入的锁的数量)

个人公众号:UncleCatMySelf
```
{
"code": 200,
"msg": "成功",
"data": "【发送成功】"
}
```

![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E5%85%AC%E4%BC%97%E5%8F%B7.png)
84 changes: 43 additions & 41 deletions h5/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@
<title>WebSocket Chat</title>
</head>
<style>
form {
width: 406px;
height: 650px;
border: 4px solid #98bcde;
border-radius: 10px;
margin: 0 auto;
background-color: #eceff9;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
form {
width: 406px;
height: 650px;
border: 4px solid #98bcde;
border-radius: 10px;
margin: 0 auto;
background-color: #eceff9;
display: flex;
flex-wrap: wrap;
justify-content: space-around;

}
h3 {
color: #92acdc;
text-align: center;
font-size: 26px;
}
textarea {
resize: none;
font-size: 20px;
width: 401px;
height: 511px;
}
.msg {
width: 324px;
height: 40px;
text-indent: 10px;
font-size: 20px;
outline: none;
}
.btn {
width: 78px;
height: 46px;
background-color: #d8f1f9;
border-radius: 6px;
border: 1px solid #98bcde;
font-size: 18px;
color: #92acdc;
font-weight: bold;
}

}
h3 {
color: #92acdc;
text-align: center;
font-size: 26px;
}
textarea {
resize: none;
font-size: 20px;
width: 401px;
height: 511px;
}
.msg {
width: 324px;
height: 40px;
text-indent: 10px;
font-size: 20px;
outline: none;
}
.btn {
width: 78px;
height: 46px;
background-color: #d8f1f9;
border-radius: 6px;
border: 1px solid #98bcde;
font-size: 18px;
color: #92acdc;
font-weight: bold;
}

</style>
<body>
<script type="text/javascript">
Expand All @@ -58,10 +58,12 @@
socket.onmessage = function(event) {
var ta = document.getElementById('responseText');
ta.value = ta.value + '\n' + event.data
console.log(event.data)
};
socket.onopen = function(event) {
var ta = document.getElementById('responseText');
ta.value = "连接开启!";
send("token-test");
};
socket.onclose = function(event) {
var ta = document.getElementById('responseText');
Expand All @@ -88,7 +90,7 @@
document.onkeydown=function(e) {
if (e.keyCode == 13) {
var message = document.getElementsByClassName('msg')[0].value;
send(message);
send("token-"+message);
}
}
</script>
Expand Down
47 changes: 0 additions & 47 deletions h5/home.html

This file was deleted.

Loading