简体   繁体   中英

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.

  1. Should I create a new socket for data only once, and remember reference, or create it whenever I need?
  2. 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: http://tools.ietf.org/html/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM