kopia lustrzana https://github.com/ge0rg/aprsdroid
implemented tcp socket timeout
rodzic
9c8f2ddead
commit
29c72b8258
|
@ -187,6 +187,10 @@
|
|||
<string name="p_filterhelp">Message filter help</string>
|
||||
<string name="p_filterhelp_summary">Online reference for APRS-IS filters</string>
|
||||
|
||||
<string name="p_sotimeout">TCP socket timeout</string>
|
||||
<string name="p_sotimeout_summary">Time before resetting the connection</string>
|
||||
<string name="p_sotimeout_entry">Timeout value in seconds (0 = disable)</string>
|
||||
|
||||
<string name="translator_credits">translator-credits</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -36,6 +36,14 @@
|
|||
<intent android:action="android.intent.action.VIEW"
|
||||
android:data="http://www.aprs-is.net/javAPRSFilter.aspx" />
|
||||
</Preference>
|
||||
<EditTextPreference
|
||||
android:key="tcp.sotimeout"
|
||||
android:inputType="number"
|
||||
android:title="@string/p_sotimeout"
|
||||
android:summary="@string/p_sotimeout_summary"
|
||||
android:defaultValue="120"
|
||||
android:dialogTitle="@string/p_sotimeout_entry" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -9,6 +9,7 @@ import _root_.java.net.{InetAddress, Socket}
|
|||
class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUploader(prefs) {
|
||||
val TAG = "TcpUploader"
|
||||
val hostname = prefs.getString("tcp.server", "euro.aprs2.net")
|
||||
val so_timeout = prefs.getStringInt("tcp.sotimeout", 120)
|
||||
var conn : TcpSocketThread = null
|
||||
|
||||
createConnection()
|
||||
|
@ -59,6 +60,7 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUpl
|
|||
this.synchronized {
|
||||
socket = new Socket(host, port)
|
||||
socket.setKeepAlive(true)
|
||||
socket.setSoTimeout(so_timeout*1000)
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
socket.getInputStream()), 256)
|
||||
writer = new PrintWriter(new OutputStreamWriter(
|
||||
|
@ -93,6 +95,10 @@ class TcpUploader(service : AprsService, prefs : PrefsWrapper) extends AprsIsUpl
|
|||
init_socket()
|
||||
}
|
||||
} catch {
|
||||
case se : java.net.SocketTimeoutException =>
|
||||
Log.i(TAG, "restarting due to timeout")
|
||||
shutdown()
|
||||
init_socket()
|
||||
case e : Exception => Log.d(TAG, "Exception " + e)
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue