Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4.  
  5. public class Client {
  6.     private Socket s = null;
  7.     private DataInputStream in;
  8.     private DataOutputStream out;
  9.     private String toServer;
  10.     private String fromServer;
  11.    
  12.    
  13.     public Client(String ip, int port){
  14.         try{
  15.             s = new Socket(ip, port);
  16.             in = new DataInputStream(s.getInputStream());
  17.             out = new DataOutputStream(s.getOutputStream());
  18.             while(true){
  19.                 toServer = "hej";  //System.console().readLine();
  20.                 out.writeUTF(toServer);
  21.                 out.flush();
  22.                 fromServer = in.readUTF();
  23.                 System.out.print(fromServer);
  24.                
  25.             }
  26.         }catch (UnknownHostException e){
  27.             e.printStackTrace();
  28.         }catch (IOException e){
  29.             e.printStackTrace();
  30.         }
  31.     }              
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement