add parseHostPort utility function

http_proxy_broken
Georg Lukas 2010-06-16 03:31:10 +02:00
rodzic 9dfb374096
commit 8fef181969
2 zmienionych plików z 12 dodań i 3 usunięć

Wyświetl plik

@ -76,4 +76,12 @@ object AprsPacket {
def formatLogin(callsign : String, ssid : String, passcode : String) : String = { def formatLogin(callsign : String, ssid : String, passcode : String) : String = {
"user " + formatCallSsid(callsign, ssid) + " pass " + passcode + " vers APRSdroid 0.1" "user " + formatCallSsid(callsign, ssid) + " pass " + passcode + " vers APRSdroid 0.1"
} }
def parseHostPort(hostport : String, defaultport : Int) : (String, Int) = {
val splits = hostport.split(":")
if (splits.length == 2)
return (splits(0), splits(1).toInt)
else
return (splits(0), defaultport)
}
} }

Wyświetl plik

@ -13,9 +13,10 @@ class UdpUploader extends AprsIsUploader {
} }
def update(host : String, login : String, packet : String) : String = { def update(host : String, login : String, packet : String) : String = {
val addr = InetAddress.getByName(host) val (h, port) = AprsPacket.parseHostPort(host, 8080)
val addr = InetAddress.getByName(h)
val pbytes = (login + "\r\n" + packet + "\r\n").getBytes() val pbytes = (login + "\r\n" + packet + "\r\n").getBytes()
socket.send(new DatagramPacket(pbytes, pbytes.length, addr, 8080)) socket.send(new DatagramPacket(pbytes, pbytes.length, addr, port))
Log.d(TAG, "update(): sent '" + packet + "' to " + host) Log.d(TAG, "update(): sent '" + packet + "' to " + host)
"UDP OK" "UDP OK"
} }