Skip to content

Commit

Permalink
版本0.1.5;优化代码;修复TCP服务器关闭后无法再打开的问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
D10NGYANG committed Oct 17, 2020
1 parent 4690c8b commit 9a9cdf0
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 37 deletions.
16 changes: 16 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 4
versionName "0.1.4"
versionName "0.1.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/readme.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"0.1.2":{"content":["适配Android10深色模式;"],"author":"dlong","time":"2020.03.18"},"0.1.1":{"content":["完成全部功能与测试;","修改UI布局;","优化架构;","调整TCP的连接状态响应逻辑;"],"author":"dlong","time":"2019.12.10"},"0.0.1":{"content":["创建工程;"],"author":"dlong","time":"2019.12.05"},"0.1.3":{"content":["优化发送数据功能","抽离UDP、TCP功能为单独库"],"author":"dlong","time":"2020.07.27"}}
{"0.0.1":{"content":["创建工程;"],"author":"dlong","time":"2019.12.05"},"0.1.2":{"content":["适配Android10深色模式;"],"author":"dlong","time":"2020.03.18"},"0.1.4":{"content":["优化代码;","修复BUG;"],"author":"dlong","time":"2020.08.12"},"0.1.1":{"content":["完成全部功能与测试;","修改UI布局;","优化架构;","调整TCP的连接状态响应逻辑;"],"author":"dlong","time":"2019.12.10"},"0.1.3":{"author":"dlong","content":["优化发送数据功能;","抽离UDP、TCP功能为单独库;"],"time":"2020.07.27"},"0.1.5":{"content":["优化代码","修复TCP服务器关闭后无法再打开的问题"],"author":"dlong","time":"2020.10.17"}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.OnBtnClick
import com.dlong.dl10netassistant.BaseNetThread
import com.dlong.dl10netassistant.OnNetThreadListener
import com.dlong.networkdebugassistant.R
Expand All @@ -24,7 +22,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.lang.StringBuilder

/**
* 基本发送和接收页面
Expand Down Expand Up @@ -102,7 +99,7 @@ open class BaseSendReceiveActivity : BaseActivity() {
withContext(Dispatchers.Main) {
connectDialog?.dismiss()
showConnect(true)
showToast(resources.getString(R.string.connect_success))
showToast(ipAddress + resources.getString(R.string.connect_success))
}
}
}
Expand All @@ -112,7 +109,7 @@ open class BaseSendReceiveActivity : BaseActivity() {
withContext(Dispatchers.Main) {
disConnectDialog?.dismiss()
showConnect(false)
showToast(resources.getString(R.string.disconnect_success))
showToast(ipAddress + resources.getString(R.string.connect_failed))
}
}
}
Expand All @@ -121,8 +118,9 @@ open class BaseSendReceiveActivity : BaseActivity() {
GlobalScope.launch {
withContext(Dispatchers.Main) {
disConnectDialog?.dismiss()
showConnect(false)
showToast(resources.getString(R.string.disconnect_success))
showConnect(thread?.isConnected() == true)
showToast(ipAddress + resources.getString(R.string.disconnect_success))
updateSocketList()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.widget.CompoundButton
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.EditDialog
import com.dlong.dialog.OnBtnClick
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.databinding.ContentBaseSettingBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.OnBtnClick
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.adapter.HistoryAdapter
import com.dlong.networkdebugassistant.bean.HistoryInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.Message
import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.dlong.dialog.*
import com.dlong.dialog.ButtonDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.EditDialog
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.adapter.FolderAdapter
import com.dlong.networkdebugassistant.bean.FolderInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.dlong.networkdebugassistant.activity

import android.os.Bundle
import android.os.Message
import android.view.View
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.OnBtnClick
import com.dlong.dl10netassistant.TcpClientThread
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.bean.TcpClientConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import android.os.Bundle
import android.text.InputType
import android.view.View
import androidx.databinding.DataBindingUtil
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.EditDialog
import com.dlong.dialog.OnBtnClick
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.bean.TcpClientConfiguration
import com.dlong.networkdebugassistant.bean.UdpBroadConfiguration
import com.dlong.networkdebugassistant.constant.DBConstant
import com.dlong.networkdebugassistant.databinding.ActivityTcpClientSettingBinding
import com.dlong.networkdebugassistant.utils.StringUtils
import java.lang.StringBuilder

class TcpClientSettingActivity : BaseSettingActivity() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import android.os.Bundle
import android.text.InputType
import android.view.View
import androidx.databinding.DataBindingUtil
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.EditDialog
import com.dlong.dialog.OnBtnClick
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.bean.TcpServerConfiguration
import com.dlong.networkdebugassistant.constant.DBConstant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import android.os.Bundle
import android.text.InputType
import android.view.View
import androidx.databinding.DataBindingUtil
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.EditDialog
import com.dlong.dialog.OnBtnClick
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.bean.UdpBroadConfiguration
import com.dlong.networkdebugassistant.constant.DBConstant
import com.dlong.networkdebugassistant.databinding.ActivityUdpBroadSettingBinding
import com.dlong.networkdebugassistant.utils.StringUtils
import java.lang.StringBuilder

class UdpBroadSettingActivity : BaseSettingActivity() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import android.os.Bundle
import android.text.InputType
import android.view.View
import androidx.databinding.DataBindingUtil
import com.dlong.dialog.BaseDialog
import com.dlong.dialog.ButtonStyle
import com.dlong.dialog.EditDialog
import com.dlong.dialog.OnBtnClick
import com.dlong.networkdebugassistant.R
import com.dlong.networkdebugassistant.bean.UdpMultiConfiguration
import com.dlong.networkdebugassistant.constant.DBConstant
import com.dlong.networkdebugassistant.databinding.ActivityUdpMultiSettingBinding
import com.dlong.networkdebugassistant.utils.StringUtils
import java.lang.StringBuilder

/**
* @author D10NG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dlong.dl10netassistant

import android.util.Log
import java.net.InetSocketAddress
import java.net.ServerSocket
import java.net.Socket

Expand Down Expand Up @@ -37,18 +38,21 @@ class TcpServerThread constructor(
super.run()
try {
// 打开服务器
serverSocket = ServerSocket(mPort)
serverSocket = ServerSocket()
serverSocket.reuseAddress = true
serverSocket.bind(InetSocketAddress(mPort))
} catch (e: Exception) {
// 打开服务器失败
serverSocket = ServerSocket()
listener?.onConnectFailed("")
listenerLambda?.onConnectFailed("")
listener?.onError("", e.toString())
listenerLambda?.onError("", e.toString())
return
}
// 打开服务器成功
listener?.onConnected("")
listenerLambda?.onConnected("")
serverSocket.reuseAddress = true

isRun = true
while (isRun) {
Expand All @@ -68,8 +72,8 @@ class TcpServerThread constructor(
startAcceptSocket(key, socket)
}
}
this.close()
// 服务器关闭
serverSocket.close()
listener?.onDisconnect("")
listenerLambda?.onDisconnect("")
}
Expand Down Expand Up @@ -152,7 +156,13 @@ class TcpServerThread constructor(
}

override fun close() {
super.close()
isRun = false
try {
serverSocket.close()
} catch (e: Exception) {
listener?.onError("", e.toString())
listenerLambda?.onError("", e.toString())
}
super.close()
}
}

0 comments on commit 9a9cdf0

Please sign in to comment.