aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common-Source/OpenSim.Servers/UDPServerBase.cs
diff options
context:
space:
mode:
authorMW2007-05-24 12:16:50 +0000
committerMW2007-05-24 12:16:50 +0000
commit3376b82501000692d6dac24b051af738cdaf2737 (patch)
tree90ed0a5d4955236f011fa63fce9d555186b0d179 /Common-Source/OpenSim.Servers/UDPServerBase.cs
parentAdded "terrain save grdmap <filename> <gradientmap>" function to console. Gra... (diff)
downloadopensim-SC_OLD-3376b82501000692d6dac24b051af738cdaf2737.zip
opensim-SC_OLD-3376b82501000692d6dac24b051af738cdaf2737.tar.gz
opensim-SC_OLD-3376b82501000692d6dac24b051af738cdaf2737.tar.bz2
opensim-SC_OLD-3376b82501000692d6dac24b051af738cdaf2737.tar.xz
Some more code refactoring, plus a restructuring of the directories so that the Grid servers can be a separate solution to the region server.
Diffstat (limited to 'Common-Source/OpenSim.Servers/UDPServerBase.cs')
-rw-r--r--Common-Source/OpenSim.Servers/UDPServerBase.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/Common-Source/OpenSim.Servers/UDPServerBase.cs b/Common-Source/OpenSim.Servers/UDPServerBase.cs
new file mode 100644
index 0000000..a308052
--- /dev/null
+++ b/Common-Source/OpenSim.Servers/UDPServerBase.cs
@@ -0,0 +1,68 @@
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 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