creating simple ftp using Java
Recently I was designing a simple ftp. When a client connects to server, server create a special Socket for this connection:
Socket clientSocket = listenSocket.accept();
I want to use this socket to send commands to server and create a new one to send data. So I have two questions.
- Should 开发者_如何学运维I create a new socket for data only once, and remember reference, or create it whenever I need?
- How exactly can I Create it? On server side create a new Socket, and through clientSocket send a port number to client so it know which port it should use to send/receive data.
Appreciate Your advice!
You might look at the FTP spec here: https://www.rfc-editor.org/rfc/rfc959 Specifically, check out page 3. You'll see FTP has a passive data port which waits for connections in addition to the control connection. Also, there is a diagram on page 7 which clarifies the typical FTP approach. Replicating it would certainly be a viable strategy.
精彩评论