Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. package sample;
  2.  
  3. import javax.swing.*;
  4. import java.io.*;
  5. import java.net.Socket;
  6. import java.net.UnknownHostException;
  7.  
  8.  
  9.  
  10. public class Player {
  11. static Socket socket = null;
  12. static PrintWriter out = null;
  13. static InputStream in = null;
  14. static InputStreamReader isr = null;
  15. static ObjectOutputStream oos = null;
  16. static ObjectInputStream ois = null;
  17. static Kopia [][] k;
  18. static Object o;
  19.  
  20.  
  21. public static void main(String[]args)
  22. {
  23. try {
  24. socket = new Socket("loopback", 2300);
  25. oos = new ObjectOutputStream(socket.getOutputStream());
  26. System.out.println("Oos utworzony");
  27. ois = new ObjectInputStream(socket.getInputStream());
  28. System.out.println("Ois utworzony");
  29. out = new PrintWriter(socket.getOutputStream(), true);
  30.  
  31.  
  32.  
  33. while(true)
  34. {
  35. o = ois.readObject();
  36.  
  37. if(o instanceof String) {
  38. String s = (String)o;
  39. if (JOptionPane.showConfirmDialog(null, s, "Czy akceptujesz ponizsze slowo?",
  40. JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
  41. oos.writeObject("tak");
  42. } else {
  43. oos.writeObject(s);
  44. }
  45. ois = new ObjectInputStream(socket.getInputStream());
  46.  
  47. }
  48.  
  49. else if(o instanceof Message)
  50. {
  51. Message mg = (Message)o;
  52. oos.writeObject(mg);
  53. ois = new ObjectInputStream(socket.getInputStream());
  54. }
  55.  
  56. else if (o instanceof Kopia[][])
  57. {
  58. k = (Kopia[][])o;
  59. System.out.println("Przechwytuje");
  60. System.out.println(k[7][7].litera);
  61. System.out.println("Wysyłam");
  62. oos.writeObject(k);
  63. System.out.println("Wysłane");
  64. System.out.println("Otwieram ois");
  65. ois = new ObjectInputStream(socket.getInputStream());
  66. System.out.println("ois utworzony");
  67. }
  68. }
  69.  
  70. } catch (UnknownHostException e) {
  71. System.err.println("Nieznany host");
  72. System.exit(0);
  73. } catch (IOException e) {
  74. System.err.println("I/O err dla");
  75. e.printStackTrace();
  76. System.exit(0);
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. System.exit(0);
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement