현재 클라이언트 - 서버 응용 프로그램을 디자인하려고합니다. 사용자가 서버에 연결하고 인증이 OK이면 서버가 사용자에게 일부 파일을 보냅니다. 문제는 그 파일들이 하나의 파일로 작성된다는 것입니다.클라이언트 - 서버 응용 프로그램 파일 전송
해야 할 파일을 선택 파일
public void processFile(int id, DataOutputStream oStream, Socket socket, int tip){
String fileName;
if(tip==0){
fileName="File"+Integer.toString(Intrebari[id])+".txt";
}else{
fileName="Image"+Integer.toString(Intrebari[id])+".jpg";
}
byte[] buffer=null;
int bytesRead = 0;
FileInputStream file=null;
try {
file = new FileInputStream(fileName);
buffer = new byte[socket.getSendBufferSize()];
while((bytesRead = file.read(buffer))>0)
{
oStream.write(buffer,0,bytesRead);
}
file.close();
} catch (IOException ex) {
System.out.println(ex);
}
}
그리고 기능을 전송 기능 보내
private void send(int id) throws IOException {
os.writeBytes("sendFile" + id+"\n");
System.out.println("sendFile" + id);
generatedFiles.processFile(id, os, comunicare, 0);
if (generatedFiles.Imagini[id] == 1) {
os.writeBytes("sendImage" + id+"\n");
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(clientThread.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("sendImage" + id);
generatedFiles.processFile(id, os, comunicare, 1);
}
}
내가 os
을 언급 할 필요가 : 여기
DataOutputStream
이고
comunicare
은
Socket
유형입니다.
writeBytes
과 write
을 결합하는 것이 문제라고 생각합니다. 누구든지이 문제를 도와 줄 수 있습니까? 서버와 클라이언트가 파일과 메시지를 모두 수신하도록하려면 어떻게합니까? 서버 클라이언트 -confirms 파일 sucessfull 클라이언트가 파일 sucessfull 을 -confirms 파일 보내기 - 서버 명령 보내기 -
서버 파일 보내기 - 명령 보내기 -
서버 :
그래서 기본적으로 FTP를 개혁하고 : 당신을 도울 수있는 몇 가지 기능 당신은 그냥 파일이나 이미지 여기
가 있는지 확인하기 위해 클라이언트 측에서 메시지를 읽을 필요가 있습니다. 왜? 이 숙제가 있니? –
예, 그렇습니다. 나는 객관식 응용 프로그램을해야하므로 사용자 이름과 암호를 입력 한 다음 텍스트 파일에 저장되어있는 서버에서 질문을 다운로드하는 GUI를 사용해야합니다. –