Advertisement
hackmate

Untitled

May 6th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package Client;
  2.  
  3. import java.io.*;
  4. import java.net.Socket;
  5. import java.net.UnknownHostException;
  6.  
  7. public class Client {
  8. public static void main(String[] args) {
  9. try {
  10. String toSend = "Czesc ucze sie javy";
  11. Socket socket = new Socket("localhost", 5555);
  12.  
  13. final InputStream inputStream = socket.getInputStream();
  14. final OutputStream outputStream = socket.getOutputStream();
  15.  
  16. final BufferedReader readFromSocket = new BufferedReader(new InputStreamReader(inputStream));
  17. final DataOutputStream writeToSocket = new DataOutputStream(outputStream);
  18.  
  19. writeToSocket.writeBytes("CZESC\n");
  20. String s = null;
  21.  
  22. while ((s = readFromSocket.readLine()) != null) {
  23. System.out.println(s);
  24. if (s.equals("Hi")) {
  25. writeToSocket.writeBytes("SEND\n");
  26. }
  27. if (s.equals("OK")) {
  28. writeToSocket.writeBytes("Thanks!\n");
  29. }
  30.  
  31.  
  32. }
  33.  
  34.  
  35. readFromSocket.close();
  36. writeToSocket.close();
  37.  
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement