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

  • Home
  • SEARCH
  • 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 3321242
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:02:21+00:00 2026-05-17T23:02:21+00:00

again i have got a problem with socket programming in Android. My Problem is

  • 0

again i have got a problem with socket programming in Android. My Problem is Selector.select() returns zero that there are no SocketChannels ready for writing. And again the same code works in normal Java but does not work in Android. Here is my code:

package com.test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class WebSocketTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

  SocketChannel channel = null;

        SocketAddress socketAdress = new InetSocketAddress("10.0.0.1", 8787);

  try {
   channel = SocketChannel.open();
  } catch (IOException e) {
   Log.e("ERROR", "channel open");
  }

  try {
   channel.configureBlocking(false);
  } catch (IOException e1) {
   Log.e("ERROR", "channel blocking");
  }

  try {
   channel.connect(socketAdress);
  } catch (IOException e) {
   Log.e("ERROR", "channel connect");
  }

  try {
   while(!channel.finishConnect())
   {

   }
  } catch (IOException e1) {
   Log.e("ERROR", "channel finishConnect");
  }


  Selector selector = null;
  try {
   selector = Selector.open();
  } catch (IOException e) {
   Log.e("ERROR", "selector open");
  }
  try {
   channel.register(selector, channel.validOps());
  } catch (ClosedChannelException e) {
   Log.e("ERROR", "channel register");
  }

  boolean i = true;

  while(i)
  {
   int readyChannels = 0;
   try {
    readyChannels = selector.select();
   } catch (IOException e) {
    Log.e("ERROR", "selector select");
   }

   if(readyChannels > 0)
   {
    i = false;
   }
  }
    }
}

In Java readyChannels = 1. In Android it is 0.
Can anyone help me?

  • 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-17T23:02:22+00:00Added an answer on May 17, 2026 at 11:02 pm

    Emulator sits behind a virtual router. You need to configure Network Redirections (port forwarding) to make a certain port on emulator visible to the outside network (including your computer).

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

Sidebar

Related Questions

Got some basic problem again. I need to modify a function that previously returned
I have got my self into a problem. I have a PreferenceManager that keeps
I have got a weird problem here, and more interesting that it works fine
I got this problem that I can't just solve algorithmically. Let's say i have
Hi Again Masters Of The Web :) Now, I have got a new stupid
I have this problem again and again... and still have not a satisfactory answer...
I have a simple search box that it hidden until hover(over) and hides again
I have a series of WCF services that invoke methods on the client again
Hello again everyone, This time I have a problem with Intent & Extras. here's
i got a problem again.. $(.menu-container).animate({top:25px}, function() { $(.menu-container).animate({top:-900px}); $(.windows-container).animate({top:-730px}); }); $(.menu-container).hide(function(){ $(.webPageFrame).attr(src,); addMenuButtons('main-menu',MenuTitleMain);

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.