Advertisement
Jordimario

sdadsasd

Jan 16th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1.  
  2. package compito;
  3. import java.util.*;
  4. import java.io.*;
  5. import java.net.*;
  6. //@author Jordi Cabrera
  7. public class MyClient {
  8. public static void main(String[] args) {
  9. try{
  10. Socket s=new Socket("localhost",6969); //inizializza la connessione con la porta 6969 su localhost
  11. Scanner input = new Scanner(System.in);
  12. Scanner in = new Scanner(s.getInputStream()); //Oggetto per prendere i messaggi in arrivo dal server
  13. PrintWriter out = new PrintWriter(s.getOutputStream(), true); //Oggetto per mandare un messaggio al server
  14. int logged=0;
  15.  
  16. while(logged==0){
  17. out.println(input.nextLine()); //messaggio da mandare al server
  18. /* while(in.nextLine().equals("false"))*/ System.out.println("Username '"+in.nextLine()+"' accettato");
  19. out.println(input.nextLine()); //messaggio da mandare al server
  20. System.out.println("Password '"+in.nextLine()+"' accettato");
  21. logged=1;
  22. }
  23. s.close(); //chiude la connessione
  24.  
  25. }catch(Exception e){System.out.println(e);}
  26. }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement