aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Servers/UDPServerBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.Servers/UDPServerBase.cs')
-rw-r--r--OpenSim.Servers/UDPServerBase.cs74
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 @@
1using System;
2using System.Text;
3using System.IO;
4using System.Threading;
5using System.Net;
6using System.Net.Sockets;
7using System.Timers;
8using System.Reflection;
9using System.Collections;
10using System.Collections.Generic;
11using libsecondlife;
12using libsecondlife.Packets;
13
14namespace 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