ivanakarpuzova

5od1

Mar 28th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import java.net.InetAddress;
  6. import java.net.Socket;
  7. import java.util.Scanner;
  8.  
  9. public class TCPClient {
  10. private Socket socket;
  11. private TCPClient(InetAddress serverAddress, int serverPort) throws Exception {
  12. this.socket = new Socket(serverAddress, serverPort);
  13. }
  14. private void start() throws IOException, InterruptedException {
  15. double n1 = 1.25;
  16. Long n2 = Long.valueOf(123584124);
  17. boolean n3 = true;
  18. String n4 = "UTF String";
  19.  
  20. PrintWriter out = new PrintWriter(this.socket.getOutputStream(), true);
  21. out.println(n1);
  22. Thread.sleep(2000);
  23. out.println(n2);
  24. Thread.sleep(2000);
  25. out.println(n3);
  26. Thread.sleep(2000);
  27. out.println(n4);
  28. Thread.sleep(2000);
  29. socket.close();
  30. }
  31.  
  32. public static void main(String[] args) throws Exception {
  33. TCPClient client = new TCPClient(
  34. InetAddress.getByName("localhost"),
  35. 9876);
  36. System.out.println("\r\nConnected to Server: " + client.socket.getInetAddress());
  37. client.start();
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment