From 696685d0db3be2260fc5902878d404b2902542a1 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 5 May 2014 10:07:30 +0200 Subject: [PATCH] Replace with socket implementation --- .../src/net/osmand/plus/osmo/OsMoService.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java index e7bc9bc82b..f0c3a1b94e 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java @@ -4,25 +4,23 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.net.URL; -import java.net.URLConnection; +import java.net.Socket; public class OsMoService { - private static String TRACKER_URL = "ws://srv.osmo.mobi:4242"; - private URLConnection conn; + private static String TRACKER_SERVER = "srv.osmo.mobi"; + private static int TRACKER_PORT = 4242; private OutputStreamWriter out; private BufferedReader in; + private Socket socket; public boolean isActive() { - return conn != null; + return socket != null; } public String activate(String hash) throws IOException { - URL tu = new URL(TRACKER_URL); - conn = tu.openConnection(); - conn.connect(); - in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); - out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8"); + socket = new Socket(TRACKER_SERVER, TRACKER_PORT); + in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8")); + out = new OutputStreamWriter(socket.getOutputStream(), "UTF-8"); String t = sendCommand("auth|"+hash); t += sendCommand("session_open"); @@ -45,7 +43,8 @@ public class OsMoService { String t = sendCommand("session_close"); in.close(); out.close(); - conn = null; + socket.close(); + socket = null; return t; }