socket hang
[adBlock.git] / src / de / ub0r / android / adBlock / Proxy.java
blob48fc4bd9c6439ee2a107d097dc7d22659778cb75
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 Socket client;
57 while (!stop) {
58 client = sock.accept();
59 if (client != null) {
60 Thread t = new Thread(new Connection(client, this));
61 t.start();
64 } catch (IOException e) {
65 e.printStackTrace();
66 Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();