fork download
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4. class Server {
  5. public static void main(String[] args) {
  6. try{
  7. ServerSocket ss = new ServerSocket(6666);
  8. Socket s = ss.accept();
  9. DataInputStream dis = new DataInputStream(s.getInputStream());
  10. String str = (String)dis.readUTF();
  11. System.out.print(str);
  12. ss.close();
  13. }catch(Exception e){
  14. System.out.println(e);
  15. }
  16. }
  17. }
  18.  
  19. class Client {
  20. public static void main(String[] args) {
  21. try{
  22. Socket s = new Socket("localhost",6666);
  23. DataOutputStream dos = new DataOutputStream(s.getOutputStream());
  24. dos.writeUTF("Hello Server");
  25. dos.flush();
  26. dos.close();
  27. s.close();
  28. }catch(Exception e){
  29. System.out.println(e);
  30. }
  31. }
  32. }
Success #stdin #stdout 0.13s 41188KB
stdin
Standard input is empty
stdout
java.net.SocketException: Network is unreachable (connect failed)