Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7072145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:46:23+00:00 2026-05-28T05:46:23+00:00

So I create a Socket in my Service which is started from an Activity.

  • 0

So I create a Socket in my Service which is started from an Activity. Socket connects to my server and waits for messages which aren’t periodical, they are sent when i write them in. Messages are received fine at first when the Service is started but after I leave the phone alone and don’t send any messages, when the screen goes blank an IO exception goes off for the InputStream.readLine() meaning the socket’s dead I suppose. The process is still running and continues to run when this happens. Is this normal behavior? I thought I’d get at least 20, 30 mins before the Socket dies, not few seconds.

   Socket mSocket=new Socket(InetAddress.getByName("192.168.1.104"),4444);
BufferedReader in=new BufferedReader(new InputStreamReader(mSocket.getInputStream()));
String message;
try {
    while((message=in.readLine())!=null){
        notify(message);
    }
    } catch (IOException e) {
        notify("socket dead");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:46:24+00:00Added an answer on May 28, 2026 at 5:46 am

    You can use the WifiManager (http://developer.android.com/reference/android/net/wifi/WifiManager.html) to obtain a WifiLock to keep the network available even after the screen goes off.

    WifiManager.WifiLock lock = ((WifiManager) someContext.getSystemService(Context.WIFI_SERVICE)).createWifiLock("MyWifiLock")
    

    And once it is no longer needed:

    lock.release();
    

    You will need to add the android.permission.WAKE_LOCK permission to your manifest.

    Be aware that this will probably be pretty hard on battery life.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to create socket-based ( Binary Socket) WCF server server with WCF, C#? What
I want to create SOCKET chat(server + clients) with private messaging. When client write
We create a socket. On one side of the socket we have a server
Can we create a Silverlight Socket Server ONLY using SILVERLIGHT and XML's (NO WCF
How to create simple C# Binary socket server (Not WCF!) Who knows the Simplest
I'd like to create a service where people can enter external websites, after which
Is it possible to create a service on Azure that handles a socket (ip:port)
TCPServer.new(port) creates a server that can service requests from localhost or remote machines. But
I'm trying to create an XML-RPC server as a windows service. The XML-RPC server
I want to create a Mobile messaging service, but I don't know which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.