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

Discussion in 'Android Questions' started by abled, Jul 31, 2015.

  1. abled

    abled Member Licensed 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: Aug 2, 2015
  2. sorex

    sorex Expert Licensed 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.
     
  3. abled

    abled Member Licensed 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?
     
  4. sorex

    sorex Expert Licensed 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.
     
  5. Jaames

    Jaames Active Member Licensed 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 :)
     
  6. abled

    abled Member Licensed User

    "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: Aug 2, 2015
  7. abled

    abled Member Licensed User

    Think you Jaames, you are right and kindly. This is my first time to ask questions. late I ask , must follow your advice!:) 非常感谢你的指点!
     
  8. abled

    abled Member Licensed User

    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?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You should use AsnycStreams and handle the Error and Terminated events.
     
  10. abled

    abled Member Licensed User

    Thank you Erel, I try to read your article on AsnycStreams!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice