diff options
Moved CheckSumServer (and added UDPServerBase ) to OpenSim.Servers
Diffstat (limited to '')
-rw-r--r-- | OpenSim.Servers/UDPServerBase.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/OpenSim.Servers/UDPServerBase.cs b/OpenSim.Servers/UDPServerBase.cs new file mode 100644 index 0000000..bdbc772 --- /dev/null +++ b/OpenSim.Servers/UDPServerBase.cs | |||
@@ -0,0 +1,74 @@ | |||
1 | using System; | ||
2 | using System.Text; | ||
3 | using System.IO; | ||
4 | using System.Threading; | ||
5 | using System.Net; | ||
6 | using System.Net.Sockets; | ||
7 | using System.Timers; | ||
8 | using System.Reflection; | ||
9 | using System.Collections; | ||
10 | using System.Collections.Generic; | ||
11 | using libsecondlife; | ||
12 | using libsecondlife.Packets; | ||
13 | |||
14 | namespace OpenSim.Servers | ||
15 | { | ||
16 | public class UDPServerBase | ||
17 | { | ||
18 | |||
19 | public Socket Server; | ||
20 | protected IPEndPoint ServerIncoming; | ||
21 | protected byte[] RecvBuffer = new byte[4096]; | ||
22 | protected byte[] ZeroBuffer = new byte[8192]; | ||
23 | protected IPEndPoint ipeSender; | ||
24 | protected EndPoint epSender; | ||
25 | protected AsyncCallback ReceivedData; | ||
26 | protected int listenPort; | ||
27 | |||
28 | public UDPServerBase() | ||
29 | { | ||
30 | } | ||
31 | |||
32 | protected virtual void OnReceivedData(IAsyncResult result) | ||
33 | { | ||
34 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
35 | epSender = (EndPoint)ipeSender; | ||
36 | Packet packet = null; | ||
37 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
38 | int packetEnd = numBytes - 1; | ||
39 | |||
40 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
41 | |||
42 | |||
43 | |||
44 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
45 | } | ||
46 | |||
47 | protected virtual void AddNewClient(Packet packet) | ||
48 | { | ||
49 | } | ||
50 | |||
51 | public void ServerListener() | ||
52 | { | ||
53 | |||
54 | ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); | ||
55 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | ||
56 | Server.Bind(ServerIncoming); | ||
57 | |||
58 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
59 | epSender = (EndPoint)ipeSender; | ||
60 | ReceivedData = new AsyncCallback(this.OnReceivedData); | ||
61 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
62 | } | ||
63 | |||
64 | |||
65 | public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
66 | { | ||
67 | // find the endpoint for this circuit | ||
68 | |||
69 | } | ||
70 | |||
71 | |||
72 | } | ||
73 | } | ||
74 | |||