Reading data

Top  Previous  Next

After establishing a connection you may read data from the server by getting the java.io.InputStream associated with the connection.  To get the input stream invoke the IpClient#getInputStream method.

 

Example

 

// create new IpClient instance

IpClient client = new IpClient("www.yahoo.com",80);

                 

// establish connection

client.connect();

 

// get output stream

OutputStream out = client.getOutputStream();

                 

// send data

String command = "GET / HTTP/1.0\r\n\r\n";

out.write(command.getBytes());

out.flush();

                 

// get input stream

InputStream in = client.getInputStream();

         

// read data from server

int i = 0;

while((i = in.read()) != -1) {

 System.out.print((char)i);

}                

 

 

 

Note

 

In most cases you will want to have your data read in a separate thread to prevent blocking I/O from taking up your program resources.  





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC