-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
48 lines (40 loc) · 1.45 KB
/
Client.java
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
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) throws IOException {
String hostName = "localhost";
int portNumber = 4477;
/*
public static void runClient() {
*/
try (
Socket ServerSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(ServerSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(ServerSocket.getInputStream()));
) {
BufferedReader stdIn =
new BufferedReader(new InputStreamReader(System.in));
String fromServer;
String fromUser;
while ((fromServer = in.readLine()) != "end") {
System.out.println("Server: " + fromServer);
/* if (fromServer.equals("Bye."))
break;
*/
fromUser = stdIn.readLine();
if (fromUser != null) {
System.out.println("Client: " + fromUser);
out.println(fromUser);
}
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " +
hostName);
System.exit(1);
}
}
}