Guest User

Untitled

a guest
Feb 28th, 2016
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package myWhats;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.net.Socket;
  7. import java.net.UnknownHostException;
  8. import java.util.Scanner;
  9.  
  10. public class myWhats {
  11.  
  12. public static void main (String [] args){
  13.  
  14.  
  15. Socket sSoc = null;
  16. String fromServer=null;
  17. String user = args[0];
  18. String[] portIP = args[1].split(":",2);
  19. String ip = portIP[0];
  20. int porto = Integer.parseInt(portIP[1]);
  21. StringBuilder sb = new StringBuilder ();
  22. Scanner sc = new Scanner(System.in);
  23. String pass=null;
  24. sb.append(user);
  25. sb.append(" ");
  26.  
  27. while((args[3].length() == 0 || args[3].equals("-m")|| args[3].equals("-f")|| args[3].equals("-a")|| args[3].equals("-r")) && pass == null){
  28. System.out.println("Por favor coloque uma pass");
  29. pass = sc.nextLine();
  30. if(pass != null){
  31. sb.append(pass);
  32. sb.append(" ");
  33. }
  34. }
  35. if(!args[3].equals(pass)){
  36. sb.append(args[3]);
  37. sb.append(" ");
  38. }
  39. for(int a=4; a < args.length; a++){
  40. sb.append(args[a]);
  41. sb.append(" ");
  42. }
  43. try {
  44. sSoc = new Socket (ip,porto);
  45. ObjectInputStream in = new ObjectInputStream(sSoc.getInputStream());
  46. ObjectOutputStream out = new ObjectOutputStream(sSoc.getOutputStream());
  47. out.writeObject(sb.toString());
  48. fromServer = (String) in.readObject();
  49. System.out.println(fromServer);
  50.  
  51. sSoc.close();
  52. } catch (UnknownHostException e) {
  53. e.printStackTrace();
  54. } catch (IOException e) {
  55. e.printStackTrace();
  56. } catch (ClassNotFoundException e) {
  57. // TODO Auto-generated catch block
  58. e.printStackTrace();
  59. }
  60.  
  61. }
  62.  
  63.  
  64.  
  65. }
Add Comment
Please, Sign In to add comment