clients
This commit is contained in:
@@ -125,6 +125,7 @@ namespace Dist.SpringWebsocket
|
||||
socket_Error(this, "State=" + client.State);
|
||||
break;
|
||||
}
|
||||
//arraySegment = new ArraySegment<byte>(array);
|
||||
result = await client.ReceiveAsync(arraySegment, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
@@ -177,15 +178,22 @@ namespace Dist.SpringWebsocket
|
||||
|
||||
async void _send(string content)
|
||||
{
|
||||
if (isDebug)
|
||||
try
|
||||
{
|
||||
Debug.Log("send==\n" + content);
|
||||
if (isDebug)
|
||||
{
|
||||
Debug.Log("发送数据====================\n" + content);
|
||||
}
|
||||
ArraySegment<byte> array = new ArraySegment<byte>(Encoding.UTF8.GetBytes(content));
|
||||
sendQueue.Enqueue(array);
|
||||
if (!isSending)
|
||||
{
|
||||
await startSending(this.socket);
|
||||
}
|
||||
}
|
||||
ArraySegment<byte> array = new ArraySegment<byte>(Encoding.UTF8.GetBytes(content));
|
||||
sendQueue.Enqueue(array);
|
||||
if (!isSending)
|
||||
catch (Exception e)
|
||||
{
|
||||
await startSending(this.socket);
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,19 +383,25 @@ namespace Dist.SpringWebsocket
|
||||
receivedBuffer.Position = totalLen;
|
||||
|
||||
string msg = Encoding.UTF8.GetString(tmpBuffer, 0, totalLen);
|
||||
if (isDebug)
|
||||
{
|
||||
Debug.LogWarning("=======取得的总数据===========" + totalLen);
|
||||
Debug.LogWarning(msg);
|
||||
}
|
||||
inputSb.Append(msg);
|
||||
while (true)
|
||||
{
|
||||
int index = inputSb.ToString().IndexOf(NULL);
|
||||
if (index < 0)
|
||||
{
|
||||
// 说明数据包还不完整
|
||||
//说明数据包还不完整
|
||||
break;
|
||||
}
|
||||
string content = inputSb.ToString().Substring(0, index);
|
||||
inputSb.Remove(0, index + 1);
|
||||
if(isDebug)
|
||||
if (isDebug)
|
||||
{
|
||||
Debug.LogWarning("=======frame===========");
|
||||
Debug.LogWarning(content);
|
||||
}
|
||||
StompFrame frame = this.TransformResultFrame(content);
|
||||
@@ -422,21 +436,29 @@ namespace Dist.SpringWebsocket
|
||||
msg = inputSb.ToString();
|
||||
inputSb.Clear();
|
||||
int leftLen = 0;
|
||||
byte[] leftBytes = null;
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
byte[] leftBytes = Encoding.UTF8.GetBytes(msg);
|
||||
leftBytes = Encoding.UTF8.GetBytes(msg);
|
||||
leftLen = leftBytes.Length;
|
||||
}
|
||||
if (leftLen > 0)
|
||||
if (isDebug)
|
||||
{
|
||||
receivedBuffer.Read(tmpBuffer, 0, leftLen);
|
||||
receivedBuffer.Position = 0;
|
||||
receivedBuffer.Write(tmpBuffer, 0, leftLen);
|
||||
receivedBuffer.SetLength(leftLen);
|
||||
} else
|
||||
Debug.LogWarning("left len====" + leftLen);
|
||||
}
|
||||
if (totalLen != leftLen)
|
||||
{
|
||||
receivedBuffer.Position = 0;
|
||||
receivedBuffer.SetLength(0);
|
||||
if (leftLen > 0)
|
||||
{
|
||||
receivedBuffer.Position = 0;
|
||||
receivedBuffer.Write(leftBytes, 0, leftLen);
|
||||
receivedBuffer.Position = leftLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
receivedBuffer.Position = 0;
|
||||
receivedBuffer.SetLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user