public virtual void Close(int aCloseCode, string aCloseReason)
{
byte[] bytes;
MemoryStream ms = new MemoryStream();
string s = aCloseReason;
if (!Closed)
{
fClosedByMe = true;
if (!fClosedByPeer)
{
bytes = new byte[2];
bytes[0] = (byte)((int)aCloseCode / 256);
bytes[1] = (byte)((int)aCloseCode % 256);
ms.Write(bytes, 0, 2);
bytes = Encoding.UTF8.GetBytes(s);
while (bytes.Length > 123)
{
s = s.Substring(0, s.Length - 1);
bytes = Encoding.UTF8.GetBytes(s);
}
ms.Write(bytes, 0, bytes.Length);
SendData(true, false, false, false, WebSocketFrame.Close, ms);
}
Close();
ProcessClose(aCloseCode, aCloseReason, false);
if (ConnectionClose != null) ConnectionClose(this, aCloseCode, aCloseReason, false);
}
}