Let us start by getting a reference to the NetworkStream To the TcpClient we can use to communicate with the client.įinally, we have to tell the TcpListener to keep listening for more connections. Once there, we call _listener.EndAcceptTcpClient , NETįramework will call the HandleAcceptTcpClient method. We are passing in a reference to another method ( HandleAcceptTcpClient), which is going to do the work for us.ĭoes not block execution, instead it returns immediately. Is listening for connections, we have to tell it to do something when a client connects. Start is obvious, it just starts the TcpListener IPAddress.Any with a reference to the IP address you want to listen on.Īfter creating it, we call Start and then If you have multiple network adapters in your machine, you may want to limit which one your FTP server listens on. We create it and tell it to listen on port 21 for any IPAddress on the server. TcpClient client = _listener.EndAcceptTcpClient(result) Private void HandleAcceptTcpClient(IAsyncResult result) _listener.BeginAcceptTcpClient(HandleAcceptTcpClient, _listener) _listener = new TcpListener(IPAddress.Any, 21) The first step in building our FTP server is getting our server to listen for connections from a client. To another thread to handle the processing of commands. Once we can accept connections, we will learn to pass off those connections We will start by creating a server that can listen for connections from a client. Typically, a client connects to a server on port 21, sends some login information,Īnd gets access to the server's local filesystem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |