Advertisement
Haifisch7734

Klient

May 18th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package klient.warcaby.wykonanie;
  2.  
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. public class Klient {
  7.  
  8.     public static void main(String[] args) {
  9.         Komunikator komunikator = new Komunikator();
  10.         Socket gniazdo = null;
  11.         OutputStream strumienWyjscia = null;
  12.         InputStream strumienWejscia = null;
  13.         PrintWriter wyjscie = null;
  14.         BufferedReader wejscie = null;
  15.  
  16.         try {
  17.             gniazdo = new Socket("localhost", 7734);
  18.         } catch (UnknownHostException e) {
  19.             System.out.println("Nie znaleziono hosta");
  20.         } catch (IOException e) {
  21.             System.out.println("Nie udało się utworzyć gniazda");
  22.         }
  23.  
  24.         try {
  25.             strumienWejscia = gniazdo.getInputStream();
  26.             strumienWyjscia = gniazdo.getOutputStream();
  27.         } catch (IOException e) {
  28.             System.out.println("Nie można pobrać strumienia wejściowego");
  29.         }
  30.  
  31.         wyjscie = new PrintWriter(strumienWyjscia, true);
  32.         wejscie = new BufferedReader(new InputStreamReader(strumienWejscia));
  33.        
  34.         System.out.println(komunikator.odbierz(wejscie));
  35.         komunikator.wyslij("Klient melduje sie",wyjscie);
  36.        
  37.         try{
  38.             wyjscie.close();
  39.             wejscie.close();
  40.             strumienWyjscia.close();
  41.             strumienWejscia.close();
  42.             gniazdo.close();
  43.         }catch(IOException e){
  44.             System.out.println("Nie udało się zamknąć strumieni i gniazd");
  45.         }
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement