-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient03.java
More file actions
45 lines (43 loc) · 1.12 KB
/
Copy pathClient03.java
File metadata and controls
45 lines (43 loc) · 1.12 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package net;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class Client03 {
String ip;
int portNo;
public Client03(String ip, int portNo) {
super();
this.ip = ip;
this.portNo = portNo;
connect();
}
public void connect(){
try {
Socket sock = new Socket(ip , portNo);
System.out.println("C: 已經與伺服器連線");
InputStream is = sock.getInputStream();
OutputStream os = sock.getOutputStream();
// DataInputStream dis = new DataInputStream(is);
// DataOutputStream dos = new DataOutputStream(os);
FileOutputStream fos = new FileOutputStream
("D:\\java004\\Data\\rt.jar");
int count = 0;
byte[] b = new byte[8192];
int len = 0 ;
while ((len=is.read(b))!=-1){
fos.write(b, 0, len);
count += len;
}
System.out.println("C: 收到" + count + "位元組");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Client03 ss01 = new Client03("127.0.0.1" , 65432);
// ss01.sendData(0);
}
}