BeginAccept() public method

Begins an asynchronous request to create a new SecureSocket to accept an incoming connection request.
is a null reference (Nothing in Visual Basic). An operating system error occurs while creating the SecureSocket. The SecureSocket has been closed.
public BeginAccept ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback The delegate.
state object An object containing state information for this request.
return IAsyncResult
示例#1
0
	///<summary>Initializes a new instance of the FtpDataConnection class.</summary>
	///<param name="RemoteAddress">The address on the local FTP client to connect to.</param>
	///<returns>The PORT command string to send to the FTP server.</returns>
	public string ProcessPort(IPEndPoint RemoteAddress) {
		try {
			ListenSocket = new SecureSocket(IPAddress.Any.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
			ListenSocket.Bind(new IPEndPoint(IPAddress.Any, 0));
			ListenSocket.Listen(1);
			ListenSocket.BeginAccept(new AsyncCallback(this.OnPortAccept), ListenSocket);
			ClientSocket = new SecureSocket(RemoteAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
			ClientSocket.BeginConnect(RemoteAddress, new AsyncCallback(this.OnPortConnected), ClientSocket);
			return "PORT " + Listener.GetLocalExternalIP().ToString().Replace('.', ',') + "," + Math.Floor(((IPEndPoint)ListenSocket.LocalEndPoint).Port / 256).ToString() + "," + (((IPEndPoint)ListenSocket.LocalEndPoint).Port % 256).ToString() + "\r\n";
		} catch {
			Dispose();
			return "PORT 0,0,0,0,0,0\r\n";
		}
	}
示例#2
0
	///<summary>Starts listening on the selected IP address and port.</summary>
	///<exception cref="SocketException">There was an error while creating the listening socket.</exception>
	public void Start() {
		try {
			ListenSocket = new SecureSocket(Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
			ListenSocket.Bind(new IPEndPoint(Address, Port));
			ListenSocket.Listen(50);
			ListenSocket.BeginAccept(new AsyncCallback(this.OnAccept), ListenSocket);
		} catch {
			ListenSocket = null;
			throw new SocketException();
		}
	}
示例#3
0
	///<summary>Called when we're connected to the data port of the remote FTP server.</summary>
	///<param name="ar">The result of the asynchronous operation.</param>
	private void OnPasvConnected(IAsyncResult ar) {
		try {
			DestinationSocket.EndConnect(ar);
			ListenSocket = new SecureSocket(IPAddress.Any.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
			ListenSocket.Bind(new IPEndPoint(IPAddress.Any, 0));
			ListenSocket.Listen(1);
			ListenSocket.BeginAccept(new AsyncCallback(this.OnPasvAccept), ListenSocket);
			Parent.SendCommand("227 Entering Passive Mode (" + Listener.GetLocalInternalIP().ToString().Replace('.', ',') + "," + Math.Floor(((IPEndPoint)ListenSocket.LocalEndPoint).Port / 256).ToString() + "," + (((IPEndPoint)ListenSocket.LocalEndPoint).Port % 256).ToString() + ").\r\n");
		} catch {
			Dispose();
		}
	}