예제 #1
0
파일: DtmKex.cs 프로젝트: modulexcite/CEX
        /// <summary>
        /// Initialize the server and listen for incoming connections
        /// </summary>
        /// 
        /// <param name="Address">The servers IP Address</param>
        /// <param name="Port">The servers Port number</param>
        /// <param name="Async">Listen on a non-blocking TCP connection</param>
        /// 
        /// <exception cref="CryptoNetworkingException">Thrown if a socket error is returned</exception>
        public void Listen(IPAddress Address, int Port, bool Async = true)
        {
            _clientSocket = new TcpSocket();
            _clientSocket.Connected += new TcpSocket.ConnectedDelegate(OnServerConnected);
            _clientSocket.DataReceived += new TcpSocket.DataReceivedDelegate(OnDataReceived);

            try
            {
                if (Async)
                    _clientSocket.ListenAsync(Address, Port);
                else
                    _clientSocket.Listen(Address, Port);
            }
            catch (Exception ex)
            {
                if (SessionError != null)
                    SessionError(this, new DtmErrorEventArgs(new CryptoSocketException("DtmKex:Listen", "The server received a socket error!", ex), DtmErrorSeverity.Connection));
            }
        }
예제 #2
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 = _bufferSize;
                _clientSocket.SendBufferSize = _bufferSize;
                _isConnected = true;
            }
        }