daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.lang.*;
  2. import java.io.*;
  3. import java.net.*;
  4. import java.util.Scanner;
  5. public class Client {
  6.     public static void main(String args[]) {
  7.         try {
  8.             Socket skt = new Socket("localhost", 1234); // change localhost to server ip address if not loopback
  9.             BufferedReader in = new BufferedReader(new
  10.                     InputStreamReader(skt.getInputStream()));
  11.             Scanner kbReader = new Scanner(System.in);
  12.             PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
  13.             out.flush();
  14.             String message="";
  15.             String servermessage="";
  16.             String username,password;
  17.             String leaveOption="no";
  18.            
  19.             System.out.println("Preparing to chat...");
  20.             out.println("I am now connected to you.");
  21.             do{
  22.                 if (in.ready()){
  23.                     servermessage=in.readLine();
  24.                     System.out.println("server>: "+servermessage);
  25.                 }
  26.                 System.out.print(servermessage);
  27.                 leaveOption=kbReader.nextLine();
  28.                 out.println(leaveOption);
  29.                 username=kbReader.nextLine();
  30.                 out.println(username);
  31.                 password=kbReader.nextLine();
  32.                 out.println(password);
  33.  
  34.                
  35.                 //out.println("ok");
  36.                 //message="bye";
  37.                 //out.println("bye");
  38.                 Thread.currentThread().sleep(300); //give time for server to respond
  39.             }while (!leaveOption.equals("yes"));
  40.             System.out.println("out of do while loop");
  41.             out.close();
  42.             in.close();
  43.         }
  44.         catch(Exception e) {
  45.             e.printStackTrace();
  46.             System.out.print("Whoops! It didn't work!\n");
  47.         }
  48.     }
  49.    
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top