private void Send(byte[] buffer, int offset, int count) { if (offset == 0) { _helper.OnTcpReceived(null, buffer, count); } else { Buffer.BlockCopy(buffer, offset, _tempArray, 0, count); _helper.OnTcpReceived(null, _tempArray, count); } }
/// <summary> /// Create a new instance of the client with the specified options. /// </summary> /// <param name="handler">The handler of the events.</param> /// <param name="encryptionKey">The key which should be used to encrypt the packets.</param> /// <param name="authenticationData">The data based on which the server can authenticate this client.</param> /// <param name="ip">The ip of the server.</param> /// <param name="port">The port of the server.</param> public DoubleClient(IDoubleClientHandler handler, byte[] encryptionKey, byte[] authenticationData, IPAddress ip, int port) { lock (this) { _handler = handler; _crypto = new FixedKeyCrypto(encryptionKey); TcpHelper tcpHelper = new TcpHelper(OnTcpPacketAssembled); _tcp = new TcpClientSocket(OnTcpConnected, OnTcpConnectionFailed, ((buffer, size) => tcpHelper.OnTcpReceived(null, buffer, size)), OnTcpLostConnection); _udp = new UdpClientSocket(OnUdpReceived); _authenticationData = authenticationData; _ip = ip; _port = port; } }