-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmdClient.java
More file actions
52 lines (45 loc) · 1.38 KB
/
CmdClient.java
File metadata and controls
52 lines (45 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
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class CmdClient extends Thread {
int Currport;
public CmdClient(String[] argv){
Currport = Integer.parseInt(argv[0]);
}
public void run(){
try{
Socket sock = new Socket("localhost", Currport);
System.out.println(sock.isConnected());
while(true){
Runner(sock);
}
}
catch(IOException ioe){
System.err.println(ioe);
}
SysLib.exit();
}
public static void Runner(Socket sock) throws IOException{
try{
Scanner scan = new Scanner(System.in);
System.out.println("Enter word");
String curr = scan.nextLine();
System.out.println(sock.isConnected());
PrintWriter pout = new PrintWriter(sock.getOutputStream(), true);
pout.println(curr);
if(curr.contains("bye")){
sock.close();
}
InputStream in = sock.getInputStream();
Scanner reader = new Scanner(new InputStreamReader(in));
PrintWriter print = new PrintWriter("output.txt");
while(reader.hasNext()){
System.out.println(reader.nextLine());
Runner(sock);
}
}
catch(Exception r){
throw r;
}
}
}