lecture 06
This commit is contained in:
28 files changed
+825
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
class EchoClient {
|
||||
public static void main(String... args) throws IOException {
|
||||
var host = "127.0.0.1";
|
||||
var port = 6666;
|
||||
try (
|
||||
var s = new Socket(host, port);
|
||||
var in =
|
||||
new BufferedReader(new InputStreamReader(s.getInputStream()));
|
||||
var out =
|
||||
new PrintWriter(new OutputStreamWriter(s.getOutputStream()), true);
|
||||
var stdin =
|
||||
new BufferedReader(new InputStreamReader(System.in));
|
||||
) {
|
||||
String line, reply;
|
||||
|
||||
while (true) {
|
||||
System.out.print("> ");
|
||||
if ((line = stdin.readLine()) == null) {
|
||||
break;
|
||||
}
|
||||
out.println(line);
|
||||
if ((reply = in.readLine()) == null) {
|
||||
break;
|
||||
}
|
||||
System.out.println(reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user