Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javax.swing.*;
- import java.io.*;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class Player {
- static Socket socket = null;
- static PrintWriter out = null;
- static InputStream in = null;
- static InputStreamReader isr = null;
- static ObjectOutputStream oos = null;
- static ObjectInputStream ois = null;
- static Kopia [][] k;
- static Object o;
- public static void main(String[]args)
- {
- try {
- socket = new Socket("loopback", 2300);
- oos = new ObjectOutputStream(socket.getOutputStream());
- System.out.println("Oos utworzony");
- ois = new ObjectInputStream(socket.getInputStream());
- System.out.println("Ois utworzony");
- out = new PrintWriter(socket.getOutputStream(), true);
- while(true)
- {
- o = ois.readObject();
- if(o instanceof String) {
- String s = (String)o;
- if (JOptionPane.showConfirmDialog(null, s, "Czy akceptujesz ponizsze slowo?",
- JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
- oos.writeObject("tak");
- } else {
- oos.writeObject(s);
- }
- ois = new ObjectInputStream(socket.getInputStream());
- }
- else if(o instanceof Message)
- {
- Message mg = (Message)o;
- oos.writeObject(mg);
- ois = new ObjectInputStream(socket.getInputStream());
- }
- else if (o instanceof Kopia[][])
- {
- k = (Kopia[][])o;
- System.out.println("Przechwytuje");
- System.out.println(k[7][7].litera);
- System.out.println("Wysyłam");
- oos.writeObject(k);
- System.out.println("Wysłane");
- System.out.println("Otwieram ois");
- ois = new ObjectInputStream(socket.getInputStream());
- System.out.println("ois utworzony");
- }
- }
- } catch (UnknownHostException e) {
- System.err.println("Nieznany host");
- System.exit(0);
- } catch (IOException e) {
- System.err.println("I/O err dla");
- e.printStackTrace();
- System.exit(0);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement