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