我正在 Java 中实现套接字编程,其中我使用 BufferedReader 从客户端获取输入。但是,BufferedReader 对象采用在控制台上输入的换行符。这是我的服务器端代码:
import java.net.*;
import java.io.*;
class FTPserver {
private ServerSocket serverSocket = null;
private DataInputStream dis = null;
private DataOutputStream dos = null;
FTPserver() {
try {
String input;
serverSocket = new ServerSocket(3000);
Socket socket = null;
socket = serverSocket.accept();
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
input = dis.readUTF();
if(input.equals("ftp")) {
dos.writeUTF("ftp> ");
input = dis.readUTF();
System.out.print("opened connection to 10.10.10.212");
dos.writeUTF("Connected to 10.10.10.212\n220 (vsFTPd 3.0.2)\nName (10.10.10.212:root): ");
input = dis.readUTF();
dos.writeUTF("331 Please specify the password.\nPassword: ");
input = dis.readUTF();
dos.writeUTF("230 Login successful.\nRemote system type is UNIX\nUse binary mode to transfer files\nftp> ");
input = dis.readUTF(); //receive mget
dos.writeUTF("ftp> ");
input = dis.readUTF(); //receive mput
dos.writeUTF("ftp> ");
//input = dis.readUTF();
input = dis.readUTF(); //receive exit
dos.writeUTF("Goodbye");
input = dis.readUTF(); //receive exit
dos.writeUTF("Goodbye");
}
dis.close();
dos.close();
socket.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
FTPserver ftp = new FTPserver();
}
}
这是我的客户端代码:
import java.net.*;
import java.io.*;
import java.util.Scanner;
class FTPclient {
private DataInputStream dis = null;
private DataOutputStream dos = null;
private Socket socket = null;
达令说
相关分类