Simple test to get stream data

This commit is contained in:
Alistair McIntyre
2017-04-20 15:08:50 +12:00
parent 9817fc9093
commit 6a27dedd74
@@ -0,0 +1,70 @@
package seng302.models.parsers;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
public class InputStreamParser {
private static String currentLine;
private static BufferedReader buffer = null;
private static void readLine() {
try {
currentLine = buffer.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void runTest() {
Socket host = null;
String hostAddress = "csse-s302staff.canterbury.ac.nz";
int hostPort = 4941;
try {
host = new Socket(hostAddress, hostPort);
} catch (IOException e) {
e.printStackTrace();
}
try {
//buffer = new DataInputStream(host.getInputStream());
if (host != null) {
buffer = new BufferedReader(new InputStreamReader(host.getInputStream()));
}
} catch (IOException e) {
e.printStackTrace();
}
readLine();
boolean reading = true;
while(reading) {
System.out.println(currentLine);
readLine();
if (currentLine == null) {
reading = false;
}
}
try {
if (host != null) {
host.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
runTest();
}
}