Prawn help look, I use the following code to set the timeout, I set the timeout time is 5 seconds (5000ms), but I have to wait long to see the thrown exception I calculated about a minute or so, but I found that, regardless of how long I set the time, he is at this time, it is very depressed, seeking heroes doubts.
Set the timeout code
SocketAddress remoteAddr = new InetSocketAddress (szIP, nPort); / / Get sockaddress object
m_hSocket.connect (remoteAddr, 5000); / / set the connection timeout 5 seconds
Too long after abnormal
thrownLog.i ("hhh", e.getMessage ());
Toast.makeText (TMActivity.this, "connection timed out, please check whether the network connection is normal", Toast.LENGTH_SHORT) show ();.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Try using wifi
Reply:
You can m_hSocket.connect (remoteAddr, 5000); around with the current time, and then calculate the time difference between the two, just to see if the timeout is 5000 milliseconds, in order to determine whether this statement is running normally. Otherwise, check the other code.
Reply:
You can write your own timers:
Timer timer = new Timer ();
TimerTask tt = new TimerTask () {
@ Override
public void run () {
/ / Decision to perform the operation after a timeout
handler.sendEmptyMessage (1);
if (timer! = null) {
timer.cancel ();
timer.purge ();
System.out.println ("Off Timer!");
}
}
};
/ / Start timer
timer.schedule (tt, 30000, 1);
Reply:
You may need to figure out the difference between connection timeout and socket timeout
Reply:
What difference does it make them, you can simply do not help me to explain?
Reply:
I should add that I am part of the code in any place of it.
Reply:
This is my main code
end connection serviceSocketAddress remoteAddr = new InetSocketAddress (szIP, nPort); / / Get sockaddress object
m_hSocket = new Socket (szIP, nPort);
m_hSocket.connect (remoteAddr, 5000); / / set the connection timeout 5 seconds
m_inStream = new DataInputStream (m_hSocket.getInputStream ());
m_outStream = new DataOutputStream (m_hSocket.getOutputStream ());
I have the right to create your own timer plus this where is it?
Reply:
socket timeout socket object is executed setSoTimeout (int timeout); method, you just set the connection timeout
Reply:
Oh, how I do it, but also hope to help the heroes ah
Reply:
The same, I do not Rom, I was in the test, so I just do that IP is an IP.
Reply:
OK, resolved, see the big brother of the article, I hope successor, also refer to http://blog.csdn.net/wq105032007067/article/details/6222581
But still very grateful to you, big brother's attention. Results posted to the sub, Ha ha ha
Reply:
Thank

Reply:
socket = new Socket ();
socket.connect (new InetSocketAddress (IConstants.SERVER_IP, IConstants.SERVER_PORT), 3000);
Reply:
No comments:
Post a Comment