Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. public void run() {
  2.  
  3. try{
  4. ServerSocket ss=new ServerSocket(puerto);
  5. int contador=0;
  6. while(!end){
  7. try{
  8. ss.setSoTimeout(6000);
  9. Socket s=ss.accept();
  10.  
  11. BufferedReader input=new BufferedReader(new InputStreamReader(s.getInputStream()));
  12. PrintWriter output=new PrintWriter(s.getOutputStream());
  13. stringData=input.readLine();
  14. output.flush();
  15. contador++;
  16.  
  17. try{
  18. Thread.sleep(1000);
  19. }catch (InterruptedException e){
  20. e.printStackTrace();
  21. }
  22. output.close();
  23. s.close();
  24. }catch (SocketTimeoutException e){
  25. e.printStackTrace();
  26. }finally {
  27. end=true;
  28. }
  29.  
  30. }
  31. ss.close();
  32. }catch (IOException e){
  33. e.printStackTrace();
  34. }
  35.  
  36.  
  37.  
  38. }
  39.  
  40. public void onClick(View view) {
  41.  
  42. dirIP=editTextDirIP.getText().toString();
  43.  
  44. hebraRecibir.start();
  45. hebraEnviar.start();
  46.  
  47. while(comprobacion){
  48. if(ThreadRecibir.isEnd()){
  49. Toast.makeText(getApplicationContext(),"la hebra se ha parado",Toast.LENGTH_LONG).show();
  50. comprobacion=false;
  51. hebraRecibir.interrupt();
  52. hebraEnviar.interrupt();
  53. }
  54. }
  55.  
  56.  
  57.  
  58. }
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement