DataInputStream: readUTF() : DataInputStream « java.io « Java by API






DataInputStream: readUTF()

  
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class MainClass {
  public static void main(String[] args) throws Exception {
    String serverName = args[0];
    int port = Integer.parseInt(args[1]);

    try {
      System.out.println("Connecting to " + serverName + " on port " + port);
      Socket client = new Socket(serverName, port);

      System.out.println("Just connected to " + client.getRemoteSocketAddress());

      OutputStream outToServer = client.getOutputStream();
      DataOutputStream out = new DataOutputStream(outToServer);
      out.writeUTF("Hello from " + client.getLocalSocketAddress());

      InputStream inFromServer = client.getInputStream();
      DataInputStream in = new DataInputStream(inFromServer);
      System.out.println("Server says " + in.readUTF());

      client.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

           
         
    
  








Related examples in the same category

1.new DataInputStream(FileInputStream fileInputStream)
2.new DataInputStream(new BufferedInputStream(new FileInputStream("temp.tmp")))
3.DataInputStream: readBoolean()
4.DataInputStream: readByte()
5.DataInputStream: readChar()
6.DataInputStream: readDouble()
7.DataInputStream: readFloat()
8.DataInputStream: readInt()
9.DataInputStream: readLong()
10.DataInputStream: readShort()
11.DataInputStream: readUnsignedShort()