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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:59:29+00:00 2026-05-25T11:59:29+00:00

I wrote code for tcp-server in java, and tested with tcp-client in java and

  • 0

I wrote code for tcp-server in java, and tested with tcp-client in java and it worked well, but when I have written a tcp-server in android, I got this exception :

09-06 15:15:37.792: ERROR/ClientActivity(444): java.net.SocketException: Permission denied
09-06 15:15:37.792: ERROR/ClientActivity(444):     at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:216)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at java.net.Socket.startupSocket(Socket.java:698)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at java.net.Socket.tryAllAddresses(Socket.java:150)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at java.net.Socket.<init>(Socket.java:209)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at java.net.Socket.<init>(Socket.java:176)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at socket.android.ClientActivity$ClientThread.run(ClientActivity.java:52)
09-06 15:15:37.792: ERROR/ClientActivity(444):     at java.lang.Thread.run(Thread.java:1019)

Code for java TCP-server :

package messenger.classes;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import messenger.handlers.ClientHandler;
public class Server{
    public static final int PORT=8111;

    public static void main(String args[]){
        final Map<String, ClientHandler> clients =new ConcurrentHashMap<String, ClientHandler>();

        try {
            ServerSocket ss=new ServerSocket(PORT);
            System.out.println("Server starts listening on PORT "+PORT);
            for(Socket socket=ss.accept();socket!=null;socket=ss.accept()){
                Runnable handler = new ClientHandler(socket,clients);
                new Thread(handler).start();
            }
        } catch (IOException e) {
            e.printStackTrace();

        }
    }
}

code for android TCP-client :

package socket.android;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ClientActivity extends Activity {


    private Button connectPhones;
    private String serverIpAddress = "";
    private boolean connected = false;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        connectPhones = (Button) findViewById(R.id.btnConnect);
        connectPhones.setOnClickListener(connectListener);
    }

    private OnClickListener connectListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!connected) {
                    Thread cThread = new Thread(new ClientThread());
                    cThread.start();
            }
        }
    };

    public class ClientThread implements Runnable {

        public void run() {
            try {
                Log.d("ClientActivity", "C: Connecting...");
                Socket socket = new Socket("127.0.0.1", 8111);
                connected = true;
                while (connected) {
                    try {
                        Log.d("ClientActivity", "C: Sending command.");
                        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
                                    .getOutputStream())), true);
                            out.println("Hey Server!");
                            Log.d("ClientActivity", "C: Sent.");
                    } catch (Exception e) {
                        Log.e("ClientActivity", "S: Error", e);
                    }
                }
                socket.close();
                Log.d("ClientActivity", "C: Closed.");
            } catch (Exception e) {
                Log.e("ClientActivity", "C: Error", e);
                connected = false;
            }
        }
    }
}

what is the problem in that, and how to solve it ?

EDIT: new error :

09-06 15:33:57.533: ERROR/ClientActivity(557): java.net.ConnectException: /127.0.0.1:8014 - Connection refused
09-06 15:33:57.533: ERROR/ClientActivity(557):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at java.net.Socket.startupSocket(Socket.java:705)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at java.net.Socket.tryAllAddresses(Socket.java:150)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at java.net.Socket.<init>(Socket.java:209)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at java.net.Socket.<init>(Socket.java:176)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at socket.android.ClientActivity$ClientThread.run(ClientActivity.java:48)
09-06 15:33:57.533: ERROR/ClientActivity(557):     at java.lang.Thread.run(Thread.java:1019)
  • 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-25T11:59:29+00:00Added an answer on May 25, 2026 at 11:59 am

    Perhaps missing INTERNET permission?

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

Sidebar

Related Questions

I have a Java Client which sends UTF-8 strings to a C# TCP-Server, I'm
I have a Java client that connects to a C++ server using TCP Sockets
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote a simple server and client apps, where I can switch between TCP,
I wrote some code in C for a TCP Server that echoes whatever it
I wrote my code using this article at msdn as a primary helper My
I wrote some code to read a file in my Java Servlet class. (I'm
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
Made a new project, added main.cpp and wrote the code at this URL: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/example/echo/async_tcp_echo_server.cpp

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.