예제 #1
0
		public void CollectTonsOfDataInOneChunk()
		{
			var dataCollector = new DataCollector();
			dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
			Assert.IsEmpty(collectedDataObjects);
			var hugeByteArray = GetTestBytesWithLengthHeader(9348);
			dataCollector.ReadBytes(hugeByteArray, 0, hugeByteArray.Length);
			Assert.AreEqual(1, collectedDataObjects.Count);
		}
예제 #2
0
 public TcpSocket(Socket nativeSocket)
 {
     this.nativeSocket = nativeSocket;
     buffer = new byte[ReceiveBufferSize];
     dataCollector = new DataCollector();
     dataCollector.ObjectFinished += OnObjectFinished;
     isDisposed = false;
     Timeout = DefaultTimeout;
 }
예제 #3
0
		public void CollectData()
		{
			var dataCollector = new DataCollector();
			dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
			Assert.IsEmpty(collectedDataObjects);
			var bytePackages = SplitDataStream(CreateByteList(), 7, 7, 8, 3, 1);
			foreach (byte[] package in bytePackages)
				dataCollector.ReadBytes(package, 0, package.Length);
			Assert.AreEqual(3, collectedDataObjects.Count);
		}
예제 #4
0
		public void CollectDataWithIncompleteMessage()
		{
			var dataCollector = new DataCollector();
			dataCollector.ObjectFinished += container => collectedDataObjects.Add(container);
			var byteArray = GetTestBytesWithLengthHeader(1);
			dataCollector.ReadBytes(byteArray, 0, 0);
			dataCollector.ReadBytes(byteArray, 0, byteArray.Length - 1);
			dataCollector.ReadBytes(byteArray, byteArray.Length - 1, 1);
			Assert.AreEqual(1, collectedDataObjects.Count);
			Assert.AreEqual(1, collectedDataObjects[0].Data.Length);
			Assert.AreEqual(100, collectedDataObjects[0].Data[0]);
		}