사용자 지정 프로토콜을 쓰고 있습니다. 나는 명령 이름을 넣었고 코드는 다음과 같이 보입니다. pWriter.println("PUT");
을 다음과 같이파일 보내기 및 만들기
if(commandString.equals("PUT")){
File f = new File(currentFolder, "test.txt");
if(!f.exists())
f.createNewFile();
FileOutputStream fout = new FileOutputStream(f);
long size = 150;
long count = 0;
int bufferLeng = 0;
byte[] buffer = new byte[512];
while((bufferLeng = dis.read(buffer))>0) //dis is a data input stream.
{
count =+ bufferLeng;
fout.write(buffer);
}
System.out.println("All Good");
fout.flush();
fout.close();
}
이 명령은 클라이언트에서 서버로 전송됩니다. 이제 이걸 실행하고 파일 test.txt
을 만들었지 만 동결 상태이며 서버에 좋은 메시지가 표시되지 않습니다. 이것이 왜 쉬운가요?
서버와 클라이언트가 작동합니다!
고맙습니다.
'dis.read (버퍼)를 작동한다'블로킹 호출이다. 고객이 연결을 닫습니까? –
코드가 컴파일 될 것이라고 생각하지 않습니다. 'if (commandString.equels ("PUT")) {'commandString'이'java.lang.String'이 아닌 한 (네이밍 규약이 정확하지 않은 경우를 제외하고)'equels (String) '메소드가 존재하지 않습니다. 아마도 당신은'if (commandString.equals ("PUT")) {' –
그렇습니다. 클라이언트가 연결을 닫습니다. –