I am developing an application for android where i need to communicate from server and i did that with the help of socket programming, now i need to find Packet Loss in my connection, so is there any API or any way to find Packet Loss in socket programming.
I am attaching my code snippet where client received message from server.
try {
socket = new Socket(dstAddress, dstPort);
dataOutputStream = new DataOutputStream(
socket.getOutputStream());
dataInputStream = new DataInputStream(socket.getInputStream());
dataOutputStream.writeUTF(name);
dataOutputStream.flush();
String myArray = "";
int i=0;
while (!goOut) {
flag=0;
if (dataInputStream.available() > 0) {
msgLog += dataInputStream.readUTF();
flag=1;
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
chatMsg.setText(msgLog);
}
});
Log.d("DERE", msgLog);
myArray=msgLog+"";
Log.v("ARE", myArray);
}
//Log.v("ARE", myArray[0]);
if(flag==1)
received(myArray);
if(!msgToSend.equals("")){
dataOutputStream.writeUTF(msgToSend);
dataOutputStream.flush();
msgToSend = "";
}
}
//Looper.loop();
} catch (UnknownHostException e) {
e.printStackTrace();
final String eString = e.toString();
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, eString, Toast.LENGTH_LONG).show();
}
});