BeardedManStudios.Network.WinMobileClient.ReadAsync C# (CSharp) Méthode

ReadAsync() protected méthode

protected ReadAsync ( ) : void
Résultat void
		protected override async void ReadAsync()
		{
			DataReader reader = new DataReader(socket.InputStream);
			//reader.InputStreamOptions = InputStreamOptions.Partial;
			while (true)
			{
				try
				{
					byte[] bytes = null;
					uint messageSize = await reader.LoadAsync(sizeof(uint));
					if (messageSize != sizeof(uint))
					{
						Disconnect();

						// socket was closed
						return;
					}

					bytes = new byte[messageSize];
					reader.ReadBytes(bytes);
					messageSize = BitConverter.ToUInt32(bytes, 0);
					await reader.LoadAsync(messageSize);

					bytes = new byte[messageSize];

					// TODO:  This may read the first 4 bytes again for the size, make sure it doesn't
					reader.ReadBytes(bytes);

					//UnityEngine.Debug.LogError(bytes.Length);

					readBuffer.Clone(bytes);
					NetworkingStream stream = new NetworkingStream().Consume(this, null, readBuffer);

					DataRead(null, stream);

					if (stream.identifierType == NetworkingStream.IdentifierType.Disconnect)
					{
						OnDisconnected(ObjectMapper.Map<string>(stream));
						Disconnect();
					}
				}
				catch (Exception e)
				{
					// If this is an unknown status,
					// it means that the error is fatal and retry will likely fail.
					if (SocketError.GetStatus(e.HResult) == SocketErrorStatus.Unknown)
						throw;
					
					ErrorDisconnect(e.Message);
				}

				await Task.Delay(ThreadSpeed);
			}
		}
#endif