Skip to content

Instantly share code, notes, and snippets.

@jawith
Created May 14, 2019 08:01
Show Gist options
  • Save jawith/d64ae1c7732add2fff2b17832cdbbeb7 to your computer and use it in GitHub Desktop.
Save jawith/d64ae1c7732add2fff2b17832cdbbeb7 to your computer and use it in GitHub Desktop.
public void run() {
StringBuilder sb = new StringBuilder();
try {
Socket socket = new Socket(
defaultHostname, 80);
OutputStream out = socket.getOutputStream();
for (int ival=1; ival<=100; ival++){
out = socket.getOutputStream();
out.write(dataText.getBytes());
//Thread.sleep(500);
InputStream in = socket.getInputStream();
byte buf[] = new byte[1024];
int nbytes;
while ((nbytes = in.read(buf)) != -1) {
sb.append(new String(buf, 0, nbytes));
}
Log.i("TextValue",sb.toString());
String test = Integer.toString(ival);
}
Log.i("socket", ">> closed");
socket.close();
} catch(IOException e) {
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment