Skip to content

Commit

Permalink
Fixed last bug in communication, this time in receiving data
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianGray committed Dec 18, 2011
1 parent 304857b commit c0b929e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Alchemy/Handlers/WebSocket/DataFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,16 @@ public void Append(String aString)
/// <param name="someBytes">Some data.</param>
/// /// <param name="asFrame">For internal use inside alchemy.</param>
public abstract void Append(byte[] someBytes, bool asFrame = false);

public override string ToString()
{
var sb = new StringBuilder();
List<ArraySegment<Byte>> list = AsRaw();
foreach(var item in list)
{
sb.Append(Encoding.UTF8.GetString(item.Array));
}
return sb.ToString();
}
}
}
4 changes: 3 additions & 1 deletion src/Alchemy/Handlers/WebSocket/hybi10/DataFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public override void Append(byte[] someBytes, bool asFrame = false)
UInt64 dataLength;
if (InternalState == DataState.Empty)
{
int dataStart = _header.FromBytes(someBytes);
var headerBytes = _header.FromBytes(someBytes);
Payload.Add(new ArraySegment<byte>(headerBytes));
int dataStart = headerBytes.Length;
data = new byte[Math.Min(Convert.ToInt32(Math.Min(_header.PayloadSizeRemaining, int.MaxValue)), someBytes.Length)];
dataLength = Math.Min(_header.PayloadSizeRemaining, Convert.ToUInt64(someBytes.Length - dataStart));
Array.Copy(someBytes, dataStart, data, 0, Convert.ToInt32(dataLength));
Expand Down
6 changes: 4 additions & 2 deletions src/Alchemy/Handlers/WebSocket/hybi10/FrameHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class FrameHeader
public UInt64 PayloadSize;
public UInt64 PayloadSizeRemaining;

public int FromBytes(byte[] data)
public byte[] FromBytes(byte[] data)
{
int dataBegin = 2;
var nibble2 = (byte) (data[0] & 0x0F);
Expand Down Expand Up @@ -53,7 +53,9 @@ public int FromBytes(byte[] data)
}

OpCode = (DataFrame.OpCode) nibble2;
return dataBegin;
byte[] someBytes = new byte[dataBegin];
Array.Copy(data, 0, someBytes, 0, dataBegin);
return someBytes;
}

public byte[] ToBytes()
Expand Down

0 comments on commit c0b929e

Please sign in to comment.