Guest User

Untitled

a guest
Jul 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.Scanner;
  4.  
  5. /**
  6. @author Snilledata
  7. */
  8. public class ATMClient {
  9. private static int connectionPort = 8989;
  10. static DataInputStream in = null;
  11. static DataOutputStream out = null;
  12. static Socket ATMSocket = null;
  13.  
  14. private static final byte ASSIGNMENT_LOGIN = 0x01;
  15. private static final byte ASSIGNMENT_WITHDRAWAL = 0x02;
  16. private static final byte ASSIGNMENT_DEPOSIT = 0x03;
  17. private static final byte ASSIGNMENT_BALANCE = 0x04;
  18.  
  19. public static void main(String[] args) throws IOException {
  20. String adress = "";
  21.  
  22. try {
  23. adress = args[0];
  24. } catch (ArrayIndexOutOfBoundsException e) {
  25. System.err.println("Missing argument ip-adress");
  26. System.exit(1);
  27. }
  28. try {
  29. ATMSocket = new Socket(adress, connectionPort);
  30. in = new DataInputStream(ATMSocket.getInputStream());
  31. out = new DataOutputStream(ATMSocket.getOutputStream());
  32. } catch (UnknownHostException e) {
  33. System.err.println("Unknown host: " +adress);
  34. System.exit(1);
  35. } catch (IOException e) {
  36. System.err.println("Couldn't open connection to " + adress);
  37. System.exit(1);
  38. }
  39.  
  40.  
  41. System.out.println("Contacting bank ... ");
  42. System.out.println(get());
  43.  
  44. //Scanner scanner = new Scanner(System.in);
  45.  
  46. System.out.print("> ");
  47.  
  48. /* int menuOption = scanner.nextInt();
  49. int userInput;
  50. out.println(menuOption);
  51. while(menuOption < 2) {
  52. if(menuOption == 1) {
  53. System.out.print("> ");
  54. menuOption = scanner.nextInt();
  55. out.println(menuOption);
  56. } else if (menuOption > 2) {
  57. break;
  58. } else {
  59. System.out.println(in.readLine());
  60. userInput = scanner.nextInt();
  61. out.println(userInput);
  62. String str;
  63. do {
  64. str = in.readLine();
  65. System.out.println(str);
  66. } while (!str.startsWith("(1)"));
  67. System.out.print("> ");
  68. menuOption = scanner.nextInt();
  69. out.println(menuOption);
  70. }
  71. } */
  72.  
  73. out.close();
  74. in.close();
  75. ATMSocket.close();
  76. }
  77.  
  78. //bör använda sig av "DataInputStream"
  79. private static void send(byte instr, String params) {
  80.  
  81. }
  82.  
  83. //bör använda sig av "DataInputStream"
  84. private static String get() throws IOException{
  85. return null;
  86. }
  87. }
Add Comment
Please, Sign In to add comment