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 9008595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:58:39+00:00 2026-06-16T01:58:39+00:00

in my current project I’m using my smartphone as a server. The server is

  • 0

in my current project I’m using my smartphone as a server. The server is started when a special Card or Tag was detected via NFC. This is the part that works.

In order to achieve this I’m using an AsyncTask that gets started once the tag is scanned. The problem is now, that I am not able to stop the server when he is currently calling ServerSocket.accept(). Calling AsyncTask.cancel(true) does not stop the server while he is waiting for a connection request.

How would I go about this if I want to stop the server at some point?

Right now I’m quite clueless. My only idea was to set the timeout time for the serversocket resulting in a thrown exception. But that would mean polling ServerSocket.accept() which can’t be the only way going about this? If it is, that would be a rather poor solution in my eyes…

  • 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-06-16T01:58:40+00:00Added an answer on June 16, 2026 at 1:58 am

    One way is that you can call close() on the ServerSocket from another thread, which will throw a SocketException in accept().

    Another is to use the timeout that you were thinking about.

    See the following posts for ideas on how to implement this :

    How can I interrupt a ServerSocket accept() method?

    Java Stop Server Thread

    Close listening ServerSocket

    Stop a socket from listening on accept

    How to unblock a thread blocked on ServerSocket.accept()?

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

Sidebar

Related Questions

My current project involves using LDAP (Active Directory) and I'm using issue tracking for
As part of my current project I've been tasked with collecting URL's for various
My current project has a development web server and live web server. Developers make
This current project I've been assigned uses the Version 3.1 levels of: Microsoft.Practices.EnterpriseLibrary.Common; Microsoft.Practices.EnterpriseLibrary.Data;
This is my current project structure: pom.xml /src /main /resources hibernate.cfg.xml /META-INF persistence.xml I
On my current project we are using both binary and xml serialization to store
Our current project does not use Hibernate (for various reasons) and we are using
My current project is using the IDesign architecture, so all of my layers are
Our current project is written in ASP.NET MVC 1 using mvc-turbines (and unity) for
My current project is using a metadata file to set properties without having to

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.