Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.net.*;
- public class Client implements Runnable{
- static Scanner sc;
- static PrintWriter p;
- static Socket sock;
- public static void main(String [] args){
- try{
- sock = new Socket("localhost", 1111);
- sc = new Scanner(sock.getInputStream());
- p = new PrintWriter(sock.getOutputStream(),true);
- }catch (Exception ex){
- ex.printStackTrace();
- }
- }
- @Override
- public void run (){
- String message;
- Scanner scan = new Scanner (System.in);
- try{
- System.out.println(sc.nextLine());
- do{
- System.out.print("Enter a message: ");
- message = scan.nextLine();
- p.println(message);
- System.out.println(scan.nextLine());
- }while(!message.equalsIgnoreCase("quit"));
- sock.close();
- p.close();
- sc.close();
- }catch (Exception exb){
- exb.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement