diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim.Servers/OpenGridProtocol.cs | 183 |
1 files changed, 94 insertions, 89 deletions
diff --git a/OpenSim.Servers/OpenGridProtocol.cs b/OpenSim.Servers/OpenGridProtocol.cs index c3d7d5c..55c47b4 100644 --- a/OpenSim.Servers/OpenGridProtocol.cs +++ b/OpenSim.Servers/OpenGridProtocol.cs | |||
@@ -1,89 +1,94 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Net; | 3 | using System.Net; |
4 | using System.Net.Sockets; | 4 | using System.Net.Sockets; |
5 | using System.Text; | 5 | using System.Text; |
6 | using System.Text.RegularExpressions; | 6 | using System.Text.RegularExpressions; |
7 | using System.Threading; | 7 | using System.Threading; |
8 | using Nwc.XmlRpc; | 8 | using Nwc.XmlRpc; |
9 | using System.Collections; | 9 | using System.Collections; |
10 | 10 | ||
11 | namespace OpenSim.Servers | 11 | namespace OpenSim.Servers |
12 | { | 12 | { |
13 | public class OpenGridProtocolServer | 13 | public class OpenGridProtocolServer |
14 | { | 14 | { |
15 | 15 | ||
16 | private Thread m_workerThread; | 16 | private Thread m_workerThread; |
17 | private Socket m_listenerSocket; | 17 | private Socket m_listenerSocket; |
18 | private IPEndPoint m_IPendpoint; | 18 | private IPEndPoint m_IPendpoint; |
19 | 19 | ||
20 | private int m_port; | 20 | private int m_port; |
21 | private ArrayList m_clients; | 21 | private ArrayList m_clients; |
22 | 22 | ||
23 | private class ClientHandler { | 23 | private class ClientHandler |
24 | private Thread m_clientThread; | 24 | { |
25 | private Socket m_socketHandle; | 25 | private Thread m_clientThread; |
26 | 26 | private Socket m_socketHandle; | |
27 | public ClientHandler(Socket clientSocketHandle) { | 27 | |
28 | m_socketHandle=clientSocketHandle; | 28 | public ClientHandler(Socket clientSocketHandle) |
29 | m_clientThread = new Thread(new ThreadStart(DoWork)); | 29 | { |
30 | m_clientThread.IsBackground = true; | 30 | m_socketHandle = clientSocketHandle; |
31 | m_clientThread.Start(); | 31 | m_clientThread = new Thread(new ThreadStart(DoWork)); |
32 | } | 32 | m_clientThread.IsBackground = true; |
33 | 33 | m_clientThread.Start(); | |
34 | private void DoWork() { | 34 | } |
35 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: ClientHandler.DoWork() - Got new client"); | 35 | |
36 | this.WriteLine("OpenSim 0.1, running OGS protocol 1.0"); | 36 | private void DoWork() |
37 | 37 | { | |
38 | } | 38 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: ClientHandler.DoWork() - Got new client"); |
39 | 39 | this.WriteLine("OpenSim 0.1, running OGS protocol 1.0"); | |
40 | private void WriteLine(string theline) { | 40 | |
41 | theline+="\n"; | 41 | } |
42 | byte[] thelinebuffer = System.Text.Encoding.ASCII.GetBytes(theline.ToCharArray()); | 42 | |
43 | m_socketHandle.Send(thelinebuffer,theline.Length,0); | 43 | private void WriteLine(string theline) |
44 | } | 44 | { |
45 | } | 45 | theline += "\n"; |
46 | 46 | byte[] thelinebuffer = System.Text.Encoding.ASCII.GetBytes(theline.ToCharArray()); | |
47 | public OpenGridProtocolServer(int port) | 47 | m_socketHandle.Send(thelinebuffer, theline.Length, 0); |
48 | { | 48 | } |
49 | m_port = port; | 49 | } |
50 | } | 50 | |
51 | 51 | public OpenGridProtocolServer(int port) | |
52 | public void Start() | 52 | { |
53 | { | 53 | m_port = port; |
54 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: Start() - Opening server socket"); | 54 | } |
55 | 55 | ||
56 | m_clients = new ArrayList(); | 56 | public void Start() |
57 | m_workerThread = new Thread(new ThreadStart(StartServerSocket)); | 57 | { |
58 | m_workerThread.IsBackground = true; | 58 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: Start() - Opening server socket"); |
59 | m_workerThread.Start(); | 59 | |
60 | } | 60 | m_clients = new ArrayList(); |
61 | 61 | m_workerThread = new Thread(new ThreadStart(StartServerSocket)); | |
62 | private void StartServerSocket() | 62 | m_workerThread.IsBackground = true; |
63 | { | 63 | m_workerThread.Start(); |
64 | try | 64 | } |
65 | { | 65 | |
66 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: StartServerSocket() - Spawned main thread OK"); | 66 | private void StartServerSocket() |
67 | 67 | { | |
68 | 68 | try | |
69 | m_IPendpoint = new IPEndPoint(IPAddress.Any, m_port); | 69 | { |
70 | m_listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | 70 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: StartServerSocket() - Spawned main thread OK"); |
71 | m_listenerSocket.Bind(m_IPendpoint); | 71 | |
72 | m_listenerSocket.Listen(4); | 72 | |
73 | 73 | m_IPendpoint = new IPEndPoint(IPAddress.Any, m_port); | |
74 | Socket sockethandle; | 74 | m_listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
75 | while (true) | 75 | m_listenerSocket.Bind(m_IPendpoint); |
76 | { | 76 | m_listenerSocket.Listen(4); |
77 | sockethandle = m_listenerSocket.Accept(); | 77 | |
78 | lock(m_clients.SyncRoot) { | 78 | Socket sockethandle; |
79 | m_clients.Add(new OpenGridProtocolServer.ClientHandler(sockethandle)); | 79 | while (true) |
80 | } | 80 | { |
81 | } | 81 | sockethandle = m_listenerSocket.Accept(); |
82 | } | 82 | lock (m_clients.SyncRoot) |
83 | catch (Exception e) | 83 | { |
84 | { | 84 | m_clients.Add(new OpenGridProtocolServer.ClientHandler(sockethandle)); |
85 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message); | 85 | } |
86 | } | 86 | } |
87 | } | 87 | } |
88 | } | 88 | catch (Exception e) |
89 | } | 89 | { |
90 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message); | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | ||