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
02d2c28f
Commit
02d2c28f
authored
Jun 22, 2024
by
王宇航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.5.4
連接方法新增超時時間配置
parent
ec01aa92
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
9 deletions
+22
-9
app/src/main/java/com/example/demo/MainActivity.kt
+3
-2
mylibrary/build.gradle.kts
+1
-1
mylibrary/src/main/java/com/gingersoft/connect/utils/GingerSoftConnect.kt
+7
-2
mylibrary/src/main/java/com/gingersoft/connect/utils/MyWebSocketClient.kt
+11
-4
No files found.
app/src/main/java/com/example/demo/MainActivity.kt
View file @
02d2c28f
...
@@ -31,8 +31,9 @@ class MainActivity : Activity() {
...
@@ -31,8 +31,9 @@ class MainActivity : Activity() {
tvConnect
.
isClickable
=
false
tvConnect
.
isClickable
=
false
connect
=
GingerSoftConnect
()
connect
=
GingerSoftConnect
()
msgSender
=
connect
!!
.
connect
(
msgSender
=
connect
!!
.
connect
(
"192.168.2.164"
,
"192.168.002.206"
,
12581
,
9100
,
10
,
object
:
GingerSoftConnect
.
SocketStateListener
{
object
:
GingerSoftConnect
.
SocketStateListener
{
override
fun
onOpen
()
{
override
fun
onOpen
()
{
super
.
onOpen
()
super
.
onOpen
()
...
...
mylibrary/build.gradle.kts
View file @
02d2c28f
...
@@ -55,7 +55,7 @@ afterEvaluate {
...
@@ -55,7 +55,7 @@ afterEvaluate {
groupId = "com.gingersoft.connect"
groupId = "com.gingersoft.connect"
artifactId = "Connect"
artifactId = "Connect"
version = "1.5.
3
"
version = "1.5.
4
"
// 添加 POM 配置
// 添加 POM 配置
// pom {
// pom {
// name.set("GingerSoftConnect")
// name.set("GingerSoftConnect")
...
...
mylibrary/src/main/java/com/gingersoft/connect/utils/GingerSoftConnect.kt
View file @
02d2c28f
...
@@ -7,9 +7,14 @@ class GingerSoftConnect {
...
@@ -7,9 +7,14 @@ class GingerSoftConnect {
private
var
webSocketClient
:
MyWebSocketClient
?
=
null
private
var
webSocketClient
:
MyWebSocketClient
?
=
null
fun
connect
(
ip
:
String
,
port
:
Int
,
listener
:
SocketStateListener
?):
MessageBuilder
{
fun
connect
(
ip
:
String
,
port
:
Int
,
connectOutTime
:
Int
=
10
,
listener
:
SocketStateListener
?
):
MessageBuilder
{
val
uri
=
URI
(
"ws://$ip:$port"
)
val
uri
=
URI
(
"ws://$ip:$port"
)
webSocketClient
=
MyWebSocketClient
(
uri
,
listener
)
webSocketClient
=
MyWebSocketClient
(
uri
,
connectOutTime
,
listener
)
webSocketClient
?.
connect
()
webSocketClient
?.
connect
()
// 連接成功後獲得發送類
// 連接成功後獲得發送類
return
MessageBuilder
(
this
,
webSocketClient
!!
)
return
MessageBuilder
(
this
,
webSocketClient
!!
)
...
...
mylibrary/src/main/java/com/gingersoft/connect/utils/MyWebSocketClient.kt
View file @
02d2c28f
...
@@ -4,18 +4,20 @@ import android.util.Log
...
@@ -4,18 +4,20 @@ import android.util.Log
import
com.gingersoft.connect.SendCallback
import
com.gingersoft.connect.SendCallback
import
com.gingersoft.connect.bean.MessageBuilder
import
com.gingersoft.connect.bean.MessageBuilder
import
com.gingersoft.connect.bean.SocketCallbackBean
import
com.gingersoft.connect.bean.SocketCallbackBean
import
kotlinx.coroutines.channels.Channel
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.drafts.Draft_6455
import
org.java_websocket.handshake.ServerHandshake
import
org.java_websocket.handshake.ServerHandshake
import
java.net.ConnectException
import
java.net.URI
import
java.net.URI
import
java.util.Timer
import
java.util.Timer
import
java.util.TimerTask
import
java.util.TimerTask
class
MyWebSocketClient
(
class
MyWebSocketClient
(
serverUri
:
URI
,
serverUri
:
URI
,
connectOutTime
:
Int
,
private
val
listener
:
GingerSoftConnect
.
SocketStateListener
?
private
val
listener
:
GingerSoftConnect
.
SocketStateListener
?
)
:
)
:
WebSocketClient
(
serverUri
)
{
WebSocketClient
(
serverUri
,
Draft_6455
(),
null
,
connectOutTime
)
{
private
val
map
by
lazy
{
HashMap
<
String
,
SendCallback
>()
}
private
val
map
by
lazy
{
HashMap
<
String
,
SendCallback
>()
}
private
val
timerMap
by
lazy
{
HashMap
<
String
,
Timer
>()
}
private
val
timerMap
by
lazy
{
HashMap
<
String
,
Timer
>()
}
...
@@ -39,8 +41,13 @@ class MyWebSocketClient(
...
@@ -39,8 +41,13 @@ class MyWebSocketClient(
}
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
listener
?.
onClose
(
code
,
reason
,
remote
)
status
=
if
(
reason
!=
null
&&
reason
.
contains
(
"failed to connect"
)){
status
=
2
onError
(
ConnectException
(
reason
))
3
}
else
{
listener
?.
onClose
(
code
,
reason
,
remote
)
2
}
}
}
override
fun
onError
(
ex
:
Exception
?)
{
override
fun
onError
(
ex
:
Exception
?)
{
...
...
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