-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
36 lines (28 loc) · 1.12 KB
/
Client.java
File metadata and controls
36 lines (28 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
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
public class Client {
public static void main(String[] argv) {
try {
Socket s = new Socket("localhost", 3000); // create a socket
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
DataInputStream din = new DataInputStream(s.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Kullanıcı adınızı giriniz : ");
String username = br.readLine();
dout.writeUTF(username); // send the username to the server
dout.flush();
byte[] bytes = new byte[8192];
int count;
while ((count = din.read(bytes)) > 0) { // read the bytes of file from server and print it
System.out.println(new String(bytes));
}
s.close();
} catch (IOException e) {
System.out.println(e);
}
}
}