wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
 
using Java.Net;
using Shared.Other;
 
namespace com.hdl.on
{
    public class Server : Java.Lang.Thread
    {
        private ServerSocket listener = null;
        private bool running = true;
        private string documentRoot;
        private Context context;
 
        public static int Port=22222;
 
        public static List<Socket> clientList = new List<Socket>();
 
        public Server(string documentRoot, Context context):base()
        {
            this.documentRoot = documentRoot;
            this.context = context;
            listener = new ServerSocket(Port);
        }
 
        public override void Run()
        {
            while (running)
            {
                try
                {
                    var client = listener.Accept();
 
                    new ServerHandler(documentRoot, context, client).Start();
                    clientList.Add(client);
                }
                catch (Exception e)
                {
                    Android.Util.Log.Error("Webserver", e.Message);
                }
            }
        }
 
 
 
        public void stopServer()
        {
            running = false;
            try
            {
                listener.Close();
            }
            catch (Exception e)
            {
                Android.Util.Log.Error("Webserver", e.Message);
            }
        }
 
        public static void remove(Socket s)
        {
            clientList.Remove(s);
        }
    }
}