aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Servers/OpenGridProtocol.cs
blob: 8c91b9a2f7229dbfbce78d8f08ee23867c6a8cd4 (plain)
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.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Nwc.XmlRpc;
using System.Collections;

namespace OpenSim.Servers
{
    public class OpenGridProtocolServer
    {
        
        private Thread m_workerThread;
        private TcpListener m_tcpListener;
	private int m_port;
	private ArrayList m_clients;

	private class ClientHandler {
		private Thread m_clientThread;
		private TcpClient m_socketHandle;

		public ClientHandler(TcpClient clientSocketHandle) {
			m_socketHandle=clientSocketHandle;
			m_clientThread = new Thread(new ThreadStart(DoWork));
			m_clientThread.IsBackground = true;
			m_clientThread.Start();
		}
		
		private void DoWork() {
                	OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: ClientHandler.DoWork() - Got new client");
		}
	}

        public OpenGridProtocolServer(int port)
        {
            m_port = port;
        }

        public void Start()
        {
                OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: Start() - Opening server socket");

                m_workerThread = new Thread(new ThreadStart(StartServerSocket));
                m_workerThread.IsBackground = true;
                m_workerThread.Start();
        }

        private void StartServerSocket()
        {
            try
            {
                OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: StartServerSocket() - Spawned main thread OK");
                

		m_tcpListener = new TcpListener(m_port);
                m_tcpListener.Start();

		TcpClient sockethandle;
                while (true)
                {
                    sockethandle = m_tcpListener.AcceptTcpClient();
		    m_clients.Add(new OpenGridProtocolServer.ClientHandler(sockethandle));
                }
            }
            catch (Exception e)
            {
                OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
            }
        }
    }
}