Android Question Could you tell me how I know a soket is disconnected?

abled

Member
Licensed User
Longtime User
1.we can use "socket.initional("192.168.1.100",5000) " connects Server. when the connection is broken by some reasion. the socket how to tell me that line is off ?

2. how I to stop a service by click a button?

I am chines, may be I expresstion is not clearly.

thank you!
 
Last edited:

sorex

Expert
Licensed User
Longtime User
It depends on the way the transfers work.

If you expect constant data then you can update a datetime variable at each returned buffer.

Use a timer that checks the difference between now and the last retrievel, if it is bigger than ... seconds/minutes you disconnect and reconnect again.
 
Upvote 0

abled

Member
Licensed User
Longtime User
sorex, you mean we must run a proggrame in Server and send back the local systerm time to the Client such as each 1 second , if check the time we recived is as same as priview, We kown the server or clent's connection
is offline?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
no, your app is receiving data from the server.

on each buffer you received you store the time.

you have a timer running every second or so that checks if the last received buffer time is larger than let's say 10 seconds.

if that's the case you can disconnect and reconnect to the server again.
 
Upvote 0

Jaames

Active Member
Licensed User
Longtime User
1.we can use "socket.initional("192.168.1.100",5000) " connects Server. when the connection is broken by some reasion. the socket how to tell me that line is off ?

2. how I to stop a service by click a button?

I am chines, may I express not clearly.

thank you!
Hi
Don't limit your questions to a single member ("Hi Erel...") . Usually , your question will be ignored. There is a ton of people on the forums, that are capable to help you ;) . Good luck and happy coding :)
 
Upvote 0

abled

Member
Licensed User
Longtime User
no, your app is receiving data from the server.

on each buffer you received you store the time.


you have a timer running every second or so that checks if the last received buffer time is larger than let's say 10 seconds.

if that's the case you can disconnect and reconnect to the server again.

"no, your app is receiving data from the server." show two way:
1==> The server Windows PC 'must' run a program that sends back The Time each one sencend. the app "checks if the last received buffer time is larger than let's say 10 seconds." like you to say.
2==> Otherwise how The app "your app is receiving data from the server. on each buffer you received you store the time."

if no a programe runs, The server dose not sends back time for your app to "checks if the last received buffer time is larger than let's say 10 seconds."

I am not sure if it is cerrect view that I to say! Plese give me some advices to me or how to do?
 
Last edited:
Upvote 0

abled

Member
Licensed User
Longtime User
Hi
Don't limit your questions to a single member ("Hi Erel...") . Usually , your question will be ignored. There is a ton of people on the forums, that are capable to help you ;) . Good luck and happy coding :)
Think you Jaames, you are right and kindly. This is my first time to ask questions. late I ask , must follow your advice!:) 非常感谢你的指点!
 
Upvote 0

abled

Member
Licensed User
Longtime User
no, your app is receiving data from the server.

on each buffer you received you store the time.

you have a timer running every second or so that checks if the last received buffer time is larger than let's say 10 seconds.

if that's the case you can disconnect and reconnect to the server again.
your reply means that the App is runing in android system and must as a "servier" , using app checks the client wether is sending back messages. I want to know how to jude server is closed in client ' s app?
 
Upvote 0
Top