Created
November 29, 2017 12:22
-
-
Save xtpor/0ed9ae6919492acb59275745749fad3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.*; | |
import java.util.Scanner; | |
public class Q3Test { | |
public static void main(String[] argv) throws IOException { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Connecting ..."); | |
Socket socket = new Socket("localhost", 12345); | |
DataInputStream in = new DataInputStream(socket.getInputStream()); | |
DataOutputStream out = new DataOutputStream(socket.getOutputStream()); | |
System.out.println("Connected"); | |
String action; | |
while (true) { | |
System.out.print("Action: "); | |
action = scanner.next(); | |
if (action.equals("readInt")) { | |
System.out.println(in.readInt()); | |
} else if (action.equals("readUTF")) { | |
System.out.println(in.readUTF()); | |
} else if (action.equals("writeInt")) { | |
out.writeInt(scanner.nextInt()); | |
} else if (action.equals("exit")) { | |
in.close(); | |
out.close(); | |
System.exit(0); | |
} | |
} | |
} | |
} |
herbert1228
commented
Nov 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment