Advertisement
Guest User

Untitled

a guest
Apr 21st, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package client2;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.PrintWriter;
  7. import java.net.Socket;
  8. import java.net.UnknownHostException;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.swing.JOptionPane;
  12.  
  13. public class Transfers {
  14.  
  15.     public int port = 1223;
  16.     //public String Ip = LoginForm.IP;
  17.     //public String ip = null;
  18.     public static Socket login = null;
  19.     public static Socket sock = null;
  20.     public static PrintWriter outStream = null;
  21.     private static BufferedReader inStream = null;
  22.     private static boolean ON = false;
  23.     public static String authorize = null;
  24.     public static boolean connected = true;
  25.  
  26.     public static void transfers(String IP, int port, String content) throws UnknownHostException, IOException {
  27.  
  28.  
  29.         try {
  30.             login = new Socket(IP, port);
  31.             //System.out.println("Connected for streaming");
  32.             outStream = new PrintWriter(login.getOutputStream(), true);
  33.             outStream.println(content);
  34.         } catch (UnknownHostException ex) {
  35.             Logger.getLogger(Transfers.class.getName()).log(Level.SEVERE, null, ex);
  36.         } catch (IOException ex) {
  37.             Logger.getLogger(Transfers.class.getName()).log(Level.SEVERE, null, ex);
  38.             login.close();
  39.         }
  40.     }
  41.  
  42.     public static String[] recieveArray(String IP) throws UnknownHostException, IOException {
  43.         String[] farray = null;
  44.         sock = new Socket(IP, 1224);
  45.         inStream = new BufferedReader(new InputStreamReader(sock.getInputStream()));
  46.         String count = inStream.readLine();
  47.         int counter = Integer.parseInt(count);
  48.         System.out.println("counter");
  49.         for (int i = 0; i < counter; i++) {
  50.             inStream = new BufferedReader(new InputStreamReader(sock.getInputStream()));
  51.             farray[i] = inStream.readLine();
  52.             System.out.println(farray[i]);
  53.         }
  54.         return farray;
  55.     }
  56. }
  57.  
  58.  
  59. ----------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement