-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyNetClient02.java
More file actions
50 lines (38 loc) · 1.44 KB
/
MyNetClient02.java
File metadata and controls
50 lines (38 loc) · 1.44 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
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 MyNetClient02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Socket socket = null;
InputStream is= null; // 서버가 보내는 데이터를 읽기 위한 스트림
DataInputStream dis = null; // 서버가 보내오는 데이터를 읽기 위한 보조스트림
OutputStream os = null; // 서버에 보낼 데이터를 출력하기 위한 스트림객체
DataOutputStream dos = null; // 서버에 보낼 데이터를 출력하기 위한 보조 스트림
String ip = null;
try {
socket = new Socket("10.10.0.201",12345);
ip = socket.getInetAddress().getHostAddress();
is = socket.getInputStream();
dis = new DataInputStream(is);
os = socket.getOutputStream();
dos = new DataOutputStream(os);
String message = dis.readUTF();
System.out.println(message);
int data = dis.readInt();
System.out.println("서버가 전송한 데이터 : " + data);
dos.writeUTF("안녕하세요 서버님 " + ip +" 클라이언트입니다");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}