aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/TRPC/TCPClient.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/TRPC/TCPClient.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/TRPC/TCPClient.cs141
1 files changed, 0 insertions, 141 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/TRPC/TCPClient.cs b/OpenSim/Region/ScriptEngine/Common/TRPC/TCPClient.cs
deleted file mode 100644
index 624c3bb..0000000
--- a/OpenSim/Region/ScriptEngine/Common/TRPC/TCPClient.cs
+++ /dev/null
@@ -1,141 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Collections.Generic;
29using System.Diagnostics;
30using System.Net;
31using System.Net.Sockets;
32
33namespace OpenSim.Region.ScriptEngine.Common.TRPC
34{
35 public class TCPClient : TCPCommon.ClientInterface
36 {
37 public TCPClient()
38 {
39 }
40
41 private readonly Dictionary<int, TCPSocket> Clients = new Dictionary<int, TCPSocket>();
42 private int ClientCount = 0;
43
44 public event TCPCommon.ClientConnectedDelegate ClientConnected;
45 public event TCPCommon.DataReceivedDelegate DataReceived;
46 public event TCPCommon.DataSentDelegate DataSent;
47 public event TCPCommon.CloseDelegate Close;
48 public event TCPCommon.ConnectErrorDelegate ConnectError;
49
50 /// <summary>
51 /// Creates client connection
52 /// </summary>
53 public void Connect(string RemoteHost, int RemotePort)
54 {
55 Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
56 IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(RemoteHost), RemotePort);
57 //newsock.BeginConnect(ipe, new AsyncCallback(asyncConnected), newsock);
58 newsock.Connect(ipe);
59 }
60
61 public int ConnectAndReturnID(string RemoteHost, int RemotePort)
62 {
63 Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
64 IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(RemoteHost), RemotePort);
65 //newsock.BeginConnect(ipe, new AsyncCallback(asyncConnected), newsock);
66 newsock.Connect(ipe);
67 return ProcessConnection(newsock);
68 }
69
70 public void Disconnect(int ID)
71 {
72 Clients[ID].Disconnect();
73 }
74
75// TODO: unused
76// void asyncConnected(IAsyncResult iar)
77// {
78// Socket client = (Socket)iar.AsyncState;
79// client.EndConnect(iar);
80// ProcessConnection(client);
81// }
82
83 private int ProcessConnection(Socket client)
84 {
85 try
86 {
87 int id = ClientCount++;
88 TCPSocket S = new TCPSocket(id, client);
89
90 // Add to dictionary
91 Clients.Add(id, S);
92
93 // Add event handlers
94 S.Close += new TCPSocket.CloseDelegate(S_Close);
95 S.DataReceived += new TCPSocket.DataReceivedDelegate(S_DataReceived);
96 S.DataSent += new TCPSocket.DataSentDelegate(S_DataSent);
97
98 // Start it
99 S.Start();
100
101 Debug.WriteLine("Connection established: " + client.RemoteEndPoint.ToString());
102
103 // Fire Connected-event
104 if (ClientConnected != null)
105 ClientConnected(id, client.RemoteEndPoint);
106
107 return id;
108 }
109 catch (SocketException sex)
110 {
111 if (ConnectError != null)
112 ConnectError(sex.Message);
113 }
114 return -1;
115 }
116
117 void S_DataSent(int ID, int length)
118 {
119 if (DataSent != null)
120 DataSent(ID, length);
121 }
122
123 void S_DataReceived(int ID, byte[] data, int offset, int length)
124 {
125 if (DataReceived != null)
126 DataReceived(ID, data, offset, length);
127 }
128
129 void S_Close(int ID)
130 {
131 if (Close != null)
132 Close(ID);
133 Clients.Remove(ID);
134 }
135
136 public void Send(int clientID, byte[] data, int offset, int len)
137 {
138 Clients[clientID].Send(clientID, data, offset, len);
139 }
140 }
141}