-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyNetClientExam01.java
More file actions
53 lines (42 loc) · 1.38 KB
/
MyNetClientExam01.java
File metadata and controls
53 lines (42 loc) · 1.38 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
46
47
48
49
50
51
52
53
package network;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class MyNetClientExam01 {
public static void main(String[] args) {
Socket socket = null;
InputStream is = null; // 서버가 보내는 데이터를 읽기 위한 스트림
DataInputStream dis = null; // 서버가 보내오는 데이터를 읽기 위한 보조스트림
OutputStream os = null; // 서버에 보낼 데이터를 출력하기 위한 스트림객체
DataOutputStream dos = null; // 서버에 보낼 데이터를 출력하기 위한 보조 스트림
String msg = null;
String ip = null;
int dan = 0;
try {
socket = new Socket("10.10.0.125", 12345);
ip = socket.getInetAddress().getHostAddress();
is = socket.getInputStream();
dis = new DataInputStream(is);
os = socket.getOutputStream();
dos = new DataOutputStream(os);
msg = dis.readUTF();
System.out.println(msg);
msg = dis.readUTF();
dan = 7;
System.out.println(msg + dan + "단");
dos.writeInt(dan);
msg = dis.readUTF();
System.out.print(msg);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}