Ejemplo n.º 1
0
    public async Task <ILog> Listen()
    {
        ILog error = null;

        while (clientState.Connected)
        {
            try
            {
                var buffer = new ArraySegment <byte>(new byte[64 * 1024 * 1024]);
                int read   = await socket.ReceiveAsync(buffer, SocketFlags.None);

                if (read > 0)
                {
                    Serializable.Packet packet = Serializable.Packet.Parser.ParseFrom(buffer.Take(read).ToArray());
                    packetHandler.HandlePacket(packet);
                    // MainThreadContext.RunOnMainThread(() => packetHandler.HandlePacket(packet));
                }
            }
            catch (Exception e)
            {
                clientState.Connected = false;
                if (socket == null)
                {
                    return(null);
                }
                return(new Error("[TCP] " + e));
            }
        }
        return(error);
    }
Ejemplo n.º 2
0
		public async void Send(Serializable.Packet packet)
		{
			if (!tcpClient.Active)
			{
				Debug.Log("[TCP] Sending packet failed. TCP client not active.");
				return;
			}
			await tcpClient.Send(packet.ToByteArray());
		}