@@ -22,6 +22,7 @@ private SocketClient() {
22
22
}
23
23
24
24
public void openConnection (String ip , int port ) throws IOException {
25
+ Log .v (TAG , "Connecting to " + ip + ":" + port );
25
26
socket = new Socket (ip , port );
26
27
outputStream = socket .getOutputStream ();
27
28
inputStream = socket .getInputStream ();
@@ -54,11 +55,14 @@ public synchronized void write(byte[] data) throws IOException {
54
55
public synchronized int read (int bytesToBeRead ) throws IOException {
55
56
int numBytesRead = 0 ;
56
57
int readNow ;
57
- Log .v (TAG , "To read : " + bytesToBeRead );
58
+ final long start = System .currentTimeMillis ();
59
+ Log .v (TAG , "Bytes to read : " + bytesToBeRead );
58
60
int bytesToBeReadTemp = bytesToBeRead ;
59
61
receivedData = new byte [bytesToBeRead ];
60
62
while (numBytesRead < bytesToBeRead ) {
63
+ final long start2 = System .currentTimeMillis ();
61
64
readNow = inputStream .read (receivedData , numBytesRead , bytesToBeReadTemp );
65
+ Log .v (TAG , "Bytes read: " + readNow + " in " + (System .currentTimeMillis () - start2 ) + " ms" );
62
66
if (readNow <= 0 ) {
63
67
Log .e (TAG , "Read Error: " + bytesToBeReadTemp );
64
68
return numBytesRead ;
@@ -67,7 +71,7 @@ public synchronized int read(int bytesToBeRead) throws IOException {
67
71
bytesToBeReadTemp -= readNow ;
68
72
}
69
73
}
70
- Log .v ("Bytes Read" , " " + numBytesRead );
74
+ Log .v (TAG , "Total bytes read: " + numBytesRead + " in " + ( System . currentTimeMillis () - start ) + " ms" );
71
75
return numBytesRead ;
72
76
}
73
77
@@ -84,7 +88,7 @@ public void closeConnection() {
84
88
isConnected = false ;
85
89
}
86
90
} catch (Exception e ) {
87
- e . printStackTrace ( );
91
+ Log . e ( TAG , "Error closing connection" , e );
88
92
}
89
93
}
90
94
}
0 commit comments