/// <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)); } }
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; } }