Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- namespace Phurious.Android.Blazr
- {
- /// <summary>
- /// Internal class to join the TCP client and buffer together
- /// for easy management in the server
- /// </summary>
- public class AsyncTcpClient
- {
- public delegate void DataReceivedHandler(AsyncTcpClient client);
- public event DataReceivedHandler DataReceived;
- /// <summary>
- /// The encoding to use when sending / receiving strings.
- /// </summary>
- public Encoding Encoding { get; set; }
- private TcpClient _tcpClient = null;
- private Byte[] _buffer = null;
- /// <summary>
- /// Constructor for a new Client
- /// </summary>
- /// <param name="tcpClient">The TCP client</param>
- /// <param name="buffer">The byte array buffer</param>
- public AsyncTcpClient(TcpClient tcpClient, Byte[] buffer)
- : this()
- {
- if (tcpClient == null) throw new ArgumentNullException("tcpClient is null");
- if (buffer == null) throw new ArgumentNullException("Buffer is null");
- this.TcpClient = tcpClient;
- this.Buffer = buffer;
- }
- private AsyncTcpClient()
- {
- this.Encoding = Encoding.ASCII;
- }
- /// <summary>
- /// Gets the TCP Client
- /// </summary>
- public TcpClient TcpClient
- {
- get
- {
- return _tcpClient;
- }
- set
- {
- _tcpClient = value;
- }
- }
- /// <summary>
- /// Gets the Buffer.
- /// </summary>
- public Byte[] Buffer
- {
- get
- {
- return _buffer;
- }
- set
- {
- _buffer = value;
- if (this.DataReceived != null) this.DataReceived(this);
- }
- }
- /// <summary>
- /// Gets the network stream
- /// </summary>
- public NetworkStream NetworkStream
- {
- get
- {
- return TcpClient.GetStream();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement