- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebClient.java
More file actions
Latest commit
30 lines (26 loc) · 984 Bytes
/
Copy pathWebClient.java
File metadata and controls
30 lines (26 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
importjava.io.*;
importjava.net.Socket;
publicclassWebClient {
publicstaticvoidmain(String[] args) {
try{
Socketsocket = newSocket("localhost", 8001);
FilerecvFile = newFile("client_recv.txt");
FilesendFile = newFile("client_send.txt");
FileInputStreamfis = newFileInputStream(sendFile);
FileOutputStreamfos = newFileOutputStream(recvFile);
intch;
// client_send.txt에 저장된 내용을 서버에 송신
OutputStreamoutput = socket.getOutputStream();
while((ch=fis.read())!=-1){
output.write(ch);
}
// output.write(0); // 전송의 끝을 알리기 위해 0을 송신
InputStreaminput = socket.getInputStream();
while ((ch = input.read()) != -1) {
fos.write(ch);
}
}catch (Exceptione){
e.printStackTrace();
}
}
}