Recent

Author Topic: LAMW: Suggestion jTCPSocketClient.java add TimeOut  (Read 3589 times)

ADiV

  • Jr. Member
  • **
  • Posts: 90
    • ADiV Software
LAMW: Suggestion jTCPSocketClient.java add TimeOut
« on: June 21, 2018, 10:04:03 am »
@jmpessoa

This is the code that I use for when there are connection failures it does not lengthen too much. I usually use timeout = 300ms

Code: Java  [Select][+][-]
  1. private Socket mSocket;
  2.  
  3. public void Connect(String _serverIP, int _serverPort, int _timeOut) {
  4.  
  5.           SERVER_IP   = _serverIP;         //IP address
  6.           SERVER_PORT = _serverPort;       //port number;
  7.           Boolean connected = false;
  8.  
  9.           if (mSocket != null) {
  10.                   try {
  11.                                 mSocket.close();
  12.                                 mSocket = null;
  13.                           } catch (IOException e) {
  14.                                 // TODO Auto-generated catch block
  15.                                 e.printStackTrace();
  16.                           }
  17.           }
  18.  
  19.           try {
  20.                    mSocket = new Socket();
  21.                    mSocket.connect( new InetSocketAddress(SERVER_IP, SERVER_PORT), _timeOut);
  22.                    connected = true;
  23.                   } catch (IOException e) {
  24.                           // TODO Auto-generated catch block
  25.                       e.printStackTrace();
  26.                   }
  27.  
  28.           if( connected ){
  29.            new TCPSocketClientTask().execute();
  30.            controls.pOnTCPSocketClientConnected(pascalObj);
  31.           }
  32.       }

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: LAMW: Suggestion jTCPSocketClient.java add TimeOut
« Reply #1 on: June 22, 2018, 05:05:30 pm »

Hi, tr3e!

Can you send me your complete "jTCPSocketClient.java" [and Pascal extension...]?
 
Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

ADiV

  • Jr. Member
  • **
  • Posts: 90
    • ADiV Software
Re: LAMW: Suggestion jTCPSocketClient.java add TimeOut
« Reply #2 on: July 05, 2018, 05:24:34 pm »
Attached full source code.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: LAMW: Suggestion jTCPSocketClient.java add TimeOut
« Reply #3 on: July 08, 2018, 09:09:40 pm »
Hi tr3e!

The ".rar" file  is damaged... :'(

what about some ".zip" ?

Thank you!
« Last Edit: July 08, 2018, 09:11:40 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

silvestre

  • Jr. Member
  • **
  • Posts: 76
Re: LAMW: Suggestion jTCPSocketClient.java add TimeOut
« Reply #4 on: July 08, 2018, 09:34:43 pm »
In my case, I can open it without problems. Attached copy of tr3e in format zip
For .rar files it can be used freely https://www.izarc.org/


Hi tr3e!

The ".rar" file  is damaged... :'(

what about some ".zip" ?

Thank you!

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: LAMW: Suggestion jTCPSocketClient.java add TimeOut
« Reply #5 on: July 08, 2018, 09:46:51 pm »
Hi,  silvestre!

The .zip is ok!!

Thank you!

[edited] 

Commited!!!

Thanks to All!
« Last Edit: July 08, 2018, 11:11:41 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018