이 C# 코드는 저에게 잘 작동합니다. 브라우저에서 제공되는 텍스트 데이터를 소켓을 통해 C# 서버로 디코딩합니다.
public static string GetDecodedData(byte[] buffer, int length)
{
byte b = buffer[1];
int dataLength = 0;
int totalLength = 0;
int keyIndex = 0;
if (b - 128 <= 125)
{
dataLength = b - 128;
keyIndex = 2;
totalLength = dataLength + 6;
}
if (b - 128 == 126)
{
dataLength = BitConverter.ToInt16(new byte[] { buffer[3], buffer[2] }, 0);
keyIndex = 4;
totalLength = dataLength + 8;
}
if (b - 128 == 127)
{
dataLength = (int)BitConverter.ToInt64(new byte[] { buffer[9], buffer[8], buffer[7], buffer[6], buffer[5], buffer[4], buffer[3], buffer[2] }, 0);
keyIndex = 10;
totalLength = dataLength + 14;
}
if (totalLength > length)
throw new Exception("The buffer length is small than the data length");
byte[] key = new byte[] { buffer[keyIndex], buffer[keyIndex + 1], buffer[keyIndex + 2], buffer[keyIndex + 3] };
int dataIndex = keyIndex + 4;
int count = 0;
for (int i = dataIndex; i < totalLength; i++)
{
buffer[i] = (byte)(buffer[i]^key[count % 4]);
count++;
}
return Encoding.ASCII.GetString(buffer, dataIndex, dataLength);
}
달콤한 ... 나는 월요일에 직장에서 이것을 시도 할 것이다. 나는 그것이 작동한다면 받아 들여지는 대답을 줄 것이다 ... :) – gislikonrad
마침내 내 websocket 서버에 대해이 솔루션을 살펴 보았다. 매력처럼 작동했습니다 ... 고마워, 남자 ... – gislikonrad
@ Gísli Konráð : 좋아요. WebSocket은 실제로 디버깅에 익숙하지 않습니다. – pimvdb