aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/TCPJSONStream/ClientNetworkContext.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/TCPJSONStream/ClientNetworkContext.cs')
-rw-r--r--OpenSim/Region/ClientStack/TCPJSONStream/ClientNetworkContext.cs146
1 files changed, 0 insertions, 146 deletions
diff --git a/OpenSim/Region/ClientStack/TCPJSONStream/ClientNetworkContext.cs b/OpenSim/Region/ClientStack/TCPJSONStream/ClientNetworkContext.cs
deleted file mode 100644
index b077b6a..0000000
--- a/OpenSim/Region/ClientStack/TCPJSONStream/ClientNetworkContext.cs
+++ /dev/null
@@ -1,146 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Net;
5using System.Net.Sockets;
6using System.Text;
7
8namespace OpenSim.Region.ClientStack.TCPJSONStream
9{
10 public class ClientNetworkContext
11 {
12 private Socket _socket;
13 private string _remoteAddress;
14 private string _remotePort;
15 private WebSocketConnectionStage _wsConnectionStatus = WebSocketConnectionStage.Accept;
16 private int _bytesLeft;
17 private NetworkStream _stream;
18 private byte[] _buffer;
19 public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
20
21 public ClientNetworkContext(IPEndPoint endPoint, int port, Stream stream, int buffersize, Socket sock)
22 {
23 _socket = sock;
24 _remoteAddress = endPoint.Address.ToString();
25 _remotePort = port.ToString();
26 _stream = stream as NetworkStream;
27 _buffer = new byte[buffersize];
28
29
30 }
31
32 public void BeginRead()
33 {
34 _wsConnectionStatus = WebSocketConnectionStage.Http;
35 try
36 {
37 _stream.BeginRead(_buffer, 0, _buffer.Length, OnReceive, _wsConnectionStatus);
38 }
39 catch (IOException err)
40 {
41 //m_log.Debug(err.ToString());
42 }
43 }
44
45 private void OnReceive(IAsyncResult ar)
46 {
47 try
48 {
49 int bytesRead = _stream.EndRead(ar);
50 if (bytesRead == 0)
51 {
52
53 Disconnected(this, new DisconnectedEventArgs(SocketError.ConnectionReset));
54 return;
55 }
56
57 }
58 catch (Exception)
59 {
60 }
61 }
62 /// <summary>
63 /// send a whole buffer
64 /// </summary>
65 /// <param name="buffer">buffer to send</param>
66 /// <exception cref="ArgumentNullException"></exception>
67 public void Send(byte[] buffer)
68 {
69 if (buffer == null)
70 throw new ArgumentNullException("buffer");
71 Send(buffer, 0, buffer.Length);
72 }
73
74 /// <summary>
75 /// Send data using the stream
76 /// </summary>
77 /// <param name="buffer">Contains data to send</param>
78 /// <param name="offset">Start position in buffer</param>
79 /// <param name="size">number of bytes to send</param>
80 /// <exception cref="ArgumentNullException"></exception>
81 /// <exception cref="ArgumentOutOfRangeException"></exception>
82 public void Send(byte[] buffer, int offset, int size)
83 {
84
85 if (offset + size > buffer.Length)
86 throw new ArgumentOutOfRangeException("offset", offset, "offset + size is beyond end of buffer.");
87
88 if (_stream != null && _stream.CanWrite)
89 {
90 try
91 {
92 _stream.Write(buffer, offset, size);
93 }
94 catch (IOException)
95 {
96
97 }
98 }
99
100 }
101 private void Reset()
102 {
103 if (_stream == null)
104 return;
105 _stream.Dispose();
106 _stream = null;
107 if (_socket == null)
108 return;
109 if (_socket.Connected)
110 _socket.Disconnect(true);
111 _socket = null;
112 }
113 }
114
115 public enum WebSocketConnectionStage
116 {
117 Reuse,
118 Accept,
119 Http,
120 WebSocket,
121 Closed
122 }
123
124 public enum FrameOpCodesRFC6455
125 {
126 Continue = 0x0,
127 Text = 0x1,
128 Binary = 0x2,
129 Close = 0x8,
130 Ping = 0x9,
131 Pong = 0xA
132 }
133
134 public enum DataState
135 {
136 Empty = 0,
137 Waiting = 1,
138 Receiving = 2,
139 Complete = 3,
140 Closed = 4,
141 Ping = 5,
142 Pong = 6
143 }
144
145
146}