Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GingerSoftLANInterconnection
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王宇航
GingerSoftLANInterconnection
Commits
1261c590
Commit
1261c590
authored
Aug 14, 2024
by
王宇航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.7.3
將消息處理過程放到協程作用域中,可以做一些接口操作
parent
031cee35
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
8 deletions
+18
-8
mylibrary/build.gradle.kts
+1
-1
mylibrary/src/main/java/com/gingersoft/connect/utils/MsgParser.kt
+1
-1
mylibrary/src/main/java/com/gingersoft/connect/utils/MsgProcess.kt
+2
-1
mylibrary/src/main/java/com/gingersoft/connect/utils/MyWebSocketServer.kt
+11
-3
mylibrary/src/main/java/com/gingersoft/connect/utils/SoldOutMsgProcess.kt
+3
-2
No files found.
mylibrary/build.gradle.kts
View file @
1261c590
...
@@ -55,7 +55,7 @@ afterEvaluate {
...
@@ -55,7 +55,7 @@ afterEvaluate {
groupId = "com.gingersoft.connect"
groupId = "com.gingersoft.connect"
artifactId = "Connect"
artifactId = "Connect"
version = "1.7.
2
"
version = "1.7.
3
"
// 添加 POM 配置
// 添加 POM 配置
// pom {
// pom {
// name.set("GingerSoftConnect")
// name.set("GingerSoftConnect")
...
...
mylibrary/src/main/java/com/gingersoft/connect/utils/MsgParser.kt
View file @
1261c590
...
@@ -10,7 +10,7 @@ object MsgParser {
...
@@ -10,7 +10,7 @@ object MsgParser {
val
parserMap
by
lazy
{
mutableMapOf
<
String
,
MsgProcess
>()
}
val
parserMap
by
lazy
{
mutableMapOf
<
String
,
MsgProcess
>()
}
fun
process
(
msgBean
:
MessageBean
?):
SocketCallbackBean
?
{
suspend
fun
process
(
msgBean
:
MessageBean
?):
SocketCallbackBean
?
{
return
if
(
msgBean
!=
null
)
{
return
if
(
msgBean
!=
null
)
{
val
result
=
parserMap
[
msgBean
.
action
.
toString
()]
?.
processMsg
(
msgBean
.
data
)
val
result
=
parserMap
[
msgBean
.
action
.
toString
()]
?.
processMsg
(
msgBean
.
data
)
if
(
result
!=
null
)
{
if
(
result
!=
null
)
{
...
...
mylibrary/src/main/java/com/gingersoft/connect/utils/MsgProcess.kt
View file @
1261c590
...
@@ -7,5 +7,5 @@ interface MsgProcess {
...
@@ -7,5 +7,5 @@ interface MsgProcess {
/**
/**
* 消息處理
* 消息處理
*/
*/
fun
processMsg
(
data
:
Any
?):
ResultBean
suspend
fun
processMsg
(
data
:
Any
?):
ResultBean
}
}
\ No newline at end of file
mylibrary/src/main/java/com/gingersoft/connect/utils/MyWebSocketServer.kt
View file @
1261c590
...
@@ -2,6 +2,9 @@ package com.gingersoft.connect.utils
...
@@ -2,6 +2,9 @@ package com.gingersoft.connect.utils
import
android.util.Log
import
android.util.Log
import
com.gingersoft.connect.bean.MessageBean
import
com.gingersoft.connect.bean.MessageBean
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
org.java_websocket.WebSocket
import
org.java_websocket.WebSocket
import
org.java_websocket.handshake.ClientHandshake
import
org.java_websocket.handshake.ClientHandshake
import
org.java_websocket.server.WebSocketServer
import
org.java_websocket.server.WebSocketServer
...
@@ -30,9 +33,14 @@ class MyWebSocketServer(address: InetSocketAddress) :
...
@@ -30,9 +33,14 @@ class MyWebSocketServer(address: InetSocketAddress) :
// RicePOS收到KDS要獲取食品的消息後,發送本地食品信息過去
// RicePOS收到KDS要獲取食品的消息後,發送本地食品信息過去
message
?.
let
{
message
?.
let
{
val
msg
=
GsonUtils
.
GsonToBean
(
message
,
MessageBean
::
class
.
java
)
val
msg
=
GsonUtils
.
GsonToBean
(
message
,
MessageBean
::
class
.
java
)
MsgParser
.
process
(
msg
)
?.
let
{
// 创建一个协程作用域
// 接受到消息並處理後,將結果返回回去
val
scope
=
CoroutineScope
(
Dispatchers
.
IO
)
conn
?.
send
(
GsonUtils
.
GsonString
(
it
))
// 在协程作用域中异步处理消息
scope
.
launch
{
MsgParser
.
process
(
msg
)
?.
let
{
// 接受到消息並處理後,將結果返回回去
conn
?.
send
(
GsonUtils
.
GsonString
(
it
))
}
}
}
}
}
}
}
...
...
mylibrary/src/main/java/com/gingersoft/connect/utils/SoldOutMsgProcess.kt
View file @
1261c590
...
@@ -4,7 +4,7 @@ import com.gingersoft.connect.bean.ResultBean
...
@@ -4,7 +4,7 @@ import com.gingersoft.connect.bean.ResultBean
import
com.gingersoft.connect.bean.SoldOutMsgBean
import
com.gingersoft.connect.bean.SoldOutMsgBean
interface
SoldOutMsgProcess
:
MsgProcess
{
interface
SoldOutMsgProcess
:
MsgProcess
{
override
fun
processMsg
(
data
:
Any
?):
ResultBean
{
override
suspend
fun
processMsg
(
data
:
Any
?):
ResultBean
{
val
gsonToBean
=
GsonUtils
.
GsonToBean
(
data
,
SoldOutMsgBean
::
class
.
java
)
val
gsonToBean
=
GsonUtils
.
GsonToBean
(
data
,
SoldOutMsgBean
::
class
.
java
)
if
(
gsonToBean
==
null
)
{
if
(
gsonToBean
==
null
)
{
return
ResultBean
(
false
,
"解析失敗"
)
return
ResultBean
(
false
,
"解析失敗"
)
...
@@ -12,6 +12,6 @@ interface SoldOutMsgProcess : MsgProcess {
...
@@ -12,6 +12,6 @@ interface SoldOutMsgProcess : MsgProcess {
return
processSoldOutMsg
(
gsonToBean
)
return
processSoldOutMsg
(
gsonToBean
)
}
}
fun
processSoldOutMsg
(
data
:
SoldOutMsgBean
?
):
ResultBean
suspend
fun
processSoldOutMsg
(
data
:
SoldOutMsgBean
):
ResultBean
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment