开发者

creating simple ftp using Java

开发者 https://www.devze.com 2023-01-25 04:30 出处:网络
Recently I was designing a simple ftp. When a client connects to server, server create a special Socket for this connection:

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: 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消