public static SignedStroke GetSignedStroke(Stream source) { byte[] ownerBytes = new byte[OWNER_NAME_BYTES_ARRAY_LENGTH]; source.Read(ownerBytes, 0, ownerBytes.Length); byte[] idBytes = new byte[sizeof(UInt32)]; source.Read(idBytes, 0, idBytes.Length); DrawingAttributes attributes = GetDrawingAttributes(source); StylusPointCollection points = new StylusPointCollection(); byte[] numberOfPointsBytes = new byte[sizeof(UInt32)]; source.Read(numberOfPointsBytes, 0, numberOfPointsBytes.Length); int numberOfPoints = BitConverter.ToInt32(numberOfPointsBytes, 0); for (int x = numberOfPoints; x != 0; x--) { points.Add(GetPoint(source)); } SignedStroke stroke = new SignedStroke(points, attributes); stroke.Owner = StringBitConverter.GetString(ownerBytes).Replace("\0", ""); stroke.Id = BitConverter.ToUInt32(idBytes, 0); return(stroke); }
public void Connect(IPAddress address, int port) { client = new TcpClient(); lock (client) { client.Connect(address, port); stream = client.GetStream(); stream.Write(StringBitConverter.GetBytes(LocalName, sizeof(char) * 128), 0, sizeof(char) * 128); } }
public static void Serialize(Stream target, SignedStroke stroke) { byte[] ownerBytes = StringBitConverter.GetBytes(stroke.Owner, OWNER_NAME_BYTES_ARRAY_LENGTH); target.Write(ownerBytes, 0, ownerBytes.Length); target.Write(BitConverter.GetBytes(stroke.Id), 0, sizeof(Int32)); Serialize(target, stroke.DrawingAttributes); StylusPointCollection points = stroke.StylusPoints; target.Write(BitConverter.GetBytes(points.Count), 0, sizeof(Int32)); foreach (StylusPoint point in points) { Serialize(target, point); } }
private void getNameFromRemote() { byte[] nameBuffer = new byte[sizeof(char) * 128]; remoteStream.Read(nameBuffer, 0, nameBuffer.Length); RemoteName = StringBitConverter.GetString(nameBuffer).Replace("\0", ""); }