blob: 55c47b430047b7131e19fc94f1aa2a44680d28b8 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
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 Socket m_listenerSocket;
private IPEndPoint m_IPendpoint;
private int m_port;
private ArrayList m_clients;
private class ClientHandler
{
private Thread m_clientThread;
private Socket m_socketHandle;
public ClientHandler(Socket 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");
this.WriteLine("OpenSim 0.1, running OGS protocol 1.0");
}
private void WriteLine(string theline)
{
theline += "\n";
byte[] thelinebuffer = System.Text.Encoding.ASCII.GetBytes(theline.ToCharArray());
m_socketHandle.Send(thelinebuffer, theline.Length, 0);
}
}
public OpenGridProtocolServer(int port)
{
m_port = port;
}
public void Start()
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenGridProtocol.cs: Start() - Opening server socket");
m_clients = new ArrayList();
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_IPendpoint = new IPEndPoint(IPAddress.Any, m_port);
m_listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
m_listenerSocket.Bind(m_IPendpoint);
m_listenerSocket.Listen(4);
Socket sockethandle;
while (true)
{
sockethandle = m_listenerSocket.Accept();
lock (m_clients.SyncRoot)
{
m_clients.Add(new OpenGridProtocolServer.ClientHandler(sockethandle));
}
}
}
catch (Exception e)
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
}
}
}
}
|