Advertisement
ldmohan

TCP Client

Feb 22nd, 2020
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.IOException;
  4. import java.net.InetSocketAddress;
  5. import java.net.Socket;
  6.  
  7. public class TcpClientSock {
  8.    
  9.     public static void main(String args[]) {
  10.        
  11.         Socket client = new Socket();
  12.         try {
  13.             client.connect(new  InetSocketAddress ("127.0.0.1",8888));
  14.        
  15.            
  16.              DataOutputStream out = new DataOutputStream(client.getOutputStream());
  17.              out.writeUTF(" Mohan \n");
  18.              
  19.              DataInputStream in = new DataInputStream(client.getInputStream());
  20.              
  21.               String msg = in.readUTF(); System.out.println("Receive msg: " + msg );
  22.              
  23.               out.close();
  24.               in.close();
  25.               client.close();
  26.            
  27.            
  28.         } catch (IOException e) {
  29.             // TODO Auto-generated catch block
  30.             e.printStackTrace();
  31.         }
  32.     }
  33.    
  34.    
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement