소켓은 기본적으로 스트림 스트림이므로 문제가 없어야합니다. 이렇게 보이는 프로토콜을 제안합니다.
이렇게하면 총 길이가 64KB 미만인 동안 임의의 속성을 보낼 수 있습니다. 63 비트 길이가 될 수 있고 한 번에 한 블록 씩 전송되는 파일이 계속됩니다. (8KB의 버퍼 포함)
원하는 경우 소켓을 사용하여 더 많은 파일을 보낼 수 있습니다.
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
Properties fileProperties = new Properties();
File file = new File(filename);
// send the properties
StringWriter writer = new StringWriter();
fileProperties.store(writer, "");
writer.close();
dos.writeUTF(writer.toString());
// send the length of the file
dos.writeLong(file.length());
// send the file.
byte[] bytes = new byte[8*1024];
FileInputStream fis = new FileInputStream(file);
int len;
while((len = fis.read(bytes))>0) {
dos.write(bytes, 0, len);
}
fis.close();
dos.flush();
DataInputStream dis = new DataInputStream(socket.getInputStream());
String propertiesText = dis.readUTF();
Properties properties = new Properties();
properties.load(new StringReader(propertiesText));
long lengthRemaining = dis.readLong();
FileOutputStream fos = new FileOutputStream(outFilename);
int len;
while(lengthRemaining > 0
&& (len = dis.read(bytes,0, (int) Math.min(bytes.length, lengthRemaining))) > 0) {
fos.write(bytes, 0, len);
lengthRemaining -= len;
}
fos.close();
웹 응용 프로그램에 대해 이야기하고 있습니까? 웹 응용 프로그램을 실행하는 경우 HTTP POST를 사용하여 파일과 매개 변수를 보내지 않는 이유는 무엇입니까? 예, 스트리밍을 웹 응용 프로그램으로 보낼 수 있습니다. – gigadot
@gigadot 데스크톱 컴퓨터에서 실행되는 클라이언트 및 서버 및 Swing 응용 프로그램. – Bassetts