Reading Text from a Socket - Java Network

Java examples for Network:Socket

Description

Reading Text from a Socket

Demo Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class Main {

  public void main(String[] argv) {
    try {/*from  w w w.  j  a  v a  2  s. co m*/
      Socket socket = null;
      BufferedReader rd = new BufferedReader(new InputStreamReader(
          socket.getInputStream()));

      String str;
      while ((str = rd.readLine()) != null) {
        System.out.println(str);
      }
      rd.close();
    } catch (IOException e) {
    }
  }
}

Related Tutorials