catching bind error :(
[adBlock.git] / src / de / ub0r / android / adBlock / Proxy.java
blobee85be06d667bd5f6a1b392d2414391eae05e4e6
1 /**
2 *
3 */
4 package de.ub0r.android.adBlock;
6 import java.io.IOException;
7 import java.net.ServerSocket;
8 import java.net.Socket;
10 import android.app.Service;
11 import android.content.Intent;
12 import android.os.IBinder;
13 import android.widget.Toast;
15 /**
16 * @author flx
19 public class Proxy extends Service implements Runnable {
21 private Thread proxy = null;
22 private int port = 8088;
23 private boolean stop = false;
25 /* (non-Javadoc)
26 * @see android.app.Service#onBind(android.content.Intent)
28 @Override
29 public IBinder onBind(Intent intent) {
30 return null;
33 @Override
34 public void onStart(Intent intent, int startId) {
35 super.onStart(intent, startId);
36 if (proxy == null) {
37 Toast.makeText(this, "starting proxy..", Toast.LENGTH_LONG).show();
38 proxy = new Thread(this);
39 proxy.start();
40 } else {
41 Toast.makeText(this, "proxy running", Toast.LENGTH_LONG).show();
45 @Override
46 public void onDestroy() {
47 super.onDestroy();
48 Toast.makeText(this, "stopping proxy..", Toast.LENGTH_LONG).show();
49 this.stop = true;
52 @Override
53 public void run() {
54 try {
55 ServerSocket sock = new ServerSocket(this.port);
56 sock.bind(null);
57 Socket client;
58 while (!stop) {
59 client = sock.accept();
60 if (client != null) {
61 Thread t = new Thread(new Connection(client, this));
62 t.start();
65 } catch (Exception e) {
66 e.printStackTrace();
67 Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();