With the following code an error occurs with reading the inputstream. I use the following code:
public void run() {
try {
SocketAddress sockaddr = new InetSocketAddress(nServer, nPort);
nsocket = new Socket();
nsocket.connect(sockaddr, 10 * 1000);
if (nsocket.isConnected()) {
nsocket.setSoTimeout(20 * 1000);
nis = nsocket.getInputStream();
nos = nsocket.getOutputStream();
if (nProtocol.equals("ntripv1")) {
String requestmsg = "GET /" + nMountpoint + " HTTP/1.0\r\n";
requestmsg += "User-Agent: NTRIP LefebureNTRIPClient/20131124\r\n";
requestmsg += "Accept: */*\r\n" + "Connection: close\r\n";
if (nUsername.length() > 0) {
requestmsg += "Authorization: Basic " + ToBase64(nUsername + ":" + nPassword) +"\r\n";
}
requestmsg += "\r\n";
nos.write(requestmsg.getBytes());
} else {
}
byte[] buffer = new byte[4096];
int read = nis.read(buffer, 0, 4096);
while (read != -1) {
byte[] tempdata = new byte[read];
System.arraycopy(buffer, 0, tempdata, 0, read);
try {
dataMessenger.send(Message.obtain(null, MSG_NETWORK_GOT_DATA, tempdata));
} catch (RemoteException e2) {
}
read = nis.read(buffer, 0, 4096);
}
}
} catch (SocketTimeoutException ex) {
try {
dataMessenger.send(Message.obtain(null, MSG_NETWORK_TIMEOUT));
} catch (RemoteException e2) {
}
} catch (Exception e) {
LogMessage(e.getLocalizedMessage());
e.printStackTrace();
} finally {
try {
nis.close();
nos.close();
nsocket.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
dataMessenger.send(Message.obtain(null, MSG_NETWORK_FINISHED));
} catch (RemoteException e2) {
}
}
}
The server sides works well with other applications. This code also make a connection with the server and gets some date but after a little while it quites at nis.read.
The codes is written with java 1.8 for android studio.
Does anyone have an idea to get all the information from the server and read all the information so it can be used in the application.
Update The error is given with the following line in the while-loop:
read = nis.read(buffer, 0, 4096);
Update 2 The given error is: System.err: java.net.SocketException: Connection reset