예제 #1
0
        public void StartSend(IPAddress Address, int Port, string FilePath)
        {
            // store the path
            _filePath = FilePath;
            // start listening on the port
            _clientSocket = new TcpSocket();
            // use the DataReceived callback
            _clientSocket.DataReceived += new TcpSocket.DataReceivedDelegate(OnDataReceived);
            _clientSocket.Connected    += new TcpSocket.ConnectedDelegate(OnConnected);
            // non blocking listen
            _clientSocket.ListenAsync(Address, Port);

            if (!_clientSocket.IsConnected)
            {
                // connect attempt failed
                throw new CryptoSocketException("DtmFileTransfer:BeginSendFile", "Could not connect to the remote host!", new SocketException((int)SocketError.ConnectionAborted));
            }
            else
            {
                // connection established
                _clientSocket.ReceiveBufferSize = m_bufferSize;
                _clientSocket.SendBufferSize    = m_bufferSize;
                _isConnected = true;
            }
        }