diff options
Diffstat (limited to 'Common/OpenSim.Servers/UDPServerBase.cs')
-rw-r--r-- | Common/OpenSim.Servers/UDPServerBase.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Common/OpenSim.Servers/UDPServerBase.cs b/Common/OpenSim.Servers/UDPServerBase.cs new file mode 100644 index 0000000..a308052 --- /dev/null +++ b/Common/OpenSim.Servers/UDPServerBase.cs | |||
@@ -0,0 +1,68 @@ | |||
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 | public Socket Server; | ||
19 | protected IPEndPoint ServerIncoming; | ||
20 | protected byte[] RecvBuffer = new byte[4096]; | ||
21 | protected byte[] ZeroBuffer = new byte[8192]; | ||
22 | protected IPEndPoint ipeSender; | ||
23 | protected EndPoint epSender; | ||
24 | protected AsyncCallback ReceivedData; | ||
25 | protected int listenPort; | ||
26 | |||
27 | public UDPServerBase(int port) | ||
28 | { | ||
29 | listenPort = port; | ||
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 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
43 | } | ||
44 | |||
45 | protected virtual void AddNewClient(Packet packet) | ||
46 | { | ||
47 | } | ||
48 | |||
49 | public virtual void ServerListener() | ||
50 | { | ||
51 | |||
52 | ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort); | ||
53 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | ||
54 | Server.Bind(ServerIncoming); | ||
55 | |||
56 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
57 | epSender = (EndPoint)ipeSender; | ||
58 | ReceivedData = new AsyncCallback(this.OnReceivedData); | ||
59 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
60 | } | ||
61 | |||
62 | public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode) | ||
63 | { | ||
64 | |||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||