Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 6th, 2013  |  syntax: Java  |  size: 1.79 KB  |  hits: 87  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.*;
  2. import java.net.*;
  3. import javax.swing.Timer;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6.  
  7. public class KnockKnockClient /*OC*/  /*/OC*/   extends Thread {
  8.  
  9.  
  10.  
  11.     public static void main(String[] args) throws IOException {
  12.            Thread simple = new Thread(new SimpleTask());
  13.            simple.start();
  14.      
  15.         Socket kkSocket = null;
  16.         PrintWriter out = null;
  17.         BufferedReader in = null;
  18.  
  19.         try {
  20.             kkSocket = new Socket("localhost", 4444);        
  21.             out = new PrintWriter(kkSocket.getOutputStream(), true);
  22.             in = new BufferedReader( new InputStreamReader( kkSocket.getInputStream()));          
  23.         } catch (UnknownHostException e) {
  24.             System.err.println("Don't know about host: localhost.");
  25.             System.exit(1);
  26.         }  catch (IOException e) {
  27.             System.err.println("Couldn't get I/O for the connection to: localhost.");
  28.             System.exit(1);
  29.         }
  30.  
  31.          
  32.         BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
  33.         String fromServer;
  34.         String fromUser;
  35.  
  36.         while ((fromServer = in.readLine()) != null) {
  37.             System.out.println("Server: " + fromServer);
  38.             if (fromServer.equals("Bye."))
  39.                 break;
  40.              
  41.             fromUser = stdIn.readLine();
  42.         if (fromUser != null) {
  43.                 System.out.println("Client: " + fromUser);
  44.                 out.println(fromUser);
  45.            }
  46.         }
  47.         out.close();
  48.         in.close();
  49.         stdIn.close();
  50.         kkSocket.close();        
  51.        
  52.     }
  53.        
  54.       public static boolean  isConnected = false; /*OC*/
  55.  
  56.      
  57.   }//class  KnockKnock clients