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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:43:37+00:00 2026-06-14T08:43:37+00:00

I am trying to establish a connection between Android Client and C# Server ..

  • 0

I am trying to establish a connection between Android Client and C# Server .. My server is working fine except the android client is not working even after adding internet connection permission

Here is the code :

    private void connectSocket(String a){ 

    try { 
        InetAddress serverAddr = InetAddress.getByName("192.168.0.2"); 
        Log.d("TCP", "C: Connecting....");

        Socket socket = new Socket(serverAddr,4444); 
        Log.d("TCP", "C: I dunno ...");
        //String message = "1";

        PrintWriter out = null;
        BufferedReader in = null;

        try { 
          //  Log.d("TCP", "C: Sending: '" + message + "'"); 
            out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true); 
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));                

            //out.println(message);
            while ((in.readLine()) != null) {
            txt.append(in.readLine());
            }

            Log.d("TCP", "C: Sent."); 
            Log.d("TCP", "C: Done.");               

        } catch(Exception e) { 
            Log.e("TCP", "S: Error", e); 
        } finally { 
            socket.close(); 
        } 

    } catch (UnknownHostException e) { 
        // TODO Auto-generated catch block 
        Log.e("TCP", "C: UnknownHostException", e); 
        e.printStackTrace(); 
    } catch (IOException e) { 
        // TODO Auto-generated catch block 
        Log.e("TCP", "C: IOException", e); 
        e.printStackTrace(); 
    }       
} 

And here is the Debugging Log:

11-15 02:41:58.040: W/dalvikvm(26839): threadid=1: thread exiting with uncaught exception (group=0x41c352a0)
11-15 02:41:58.075: E/AndroidRuntime(26839): FATAL EXCEPTION: main
11-15 02:41:58.075: E/AndroidRuntime(26839): android.os.NetworkOnMainThreadException
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at libcore.io.IoBridge.connect(IoBridge.java:112)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at java.net.Socket.startupSocket(Socket.java:566)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at java.net.Socket.<init>(Socket.java:225)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at com.example.socketclient.SocketCode.connectSocket(SocketCode.java:50)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at com.example.socketclient.SocketCode.access$0(SocketCode.java:44)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at com.example.socketclient.SocketCode$1.onClick(SocketCode.java:35)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.view.View.performClick(View.java:4211)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.view.View$PerformClick.run(View.java:17267)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.os.Handler.handleCallback(Handler.java:615)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.os.Looper.loop(Looper.java:137)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at android.app.ActivityThread.main(ActivityThread.java:4898)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at java.lang.reflect.Method.invokeNative(Native Method)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at java.lang.reflect.Method.invoke(Method.java:511)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
11-15 02:41:58.075: E/AndroidRuntime(26839):    at dalvik.system.NativeStart.main(Native Method)
  • 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-14T08:43:38+00:00Added an answer on June 14, 2026 at 8:43 am

    By the looks of it you are trying to perform networking operation on the main thread. Take a look at the log trace specially line android.os.NetworkOnMainThreadException.

    Android Developer: Network on Main Thread Exception

    Always do networking on a separate thread other than main. There are different ways to accomplish that as well e.g. you can use AsyncTask or start thread on your own.

    There are several posts on SO for this and Android Developer site. Here are a few links to get you going:

    Android Developer: Connecting to the network

    Android Developers Blog: Multithreading for performance

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

Sidebar

Related Questions

I'm trying to establish and udp connection between a server and an android device.
I am trying to establish connection between ZABBIX SERVER which has been installed on
I've been trying to get a basic socket connection working between my server and
I am trying to establish a connection between my mail server and a java
I'm trying to establish a second database connection to another database on another server.
HI folks, I'm trying to establish connection to a remote server using ruby socket
I am trying to establish a HTTPS connection to a server using my app.
I am currently trying to establish a connection between an ASP.NET web site project
I am trying to create an SSL Socket Server/Client between .NET and Java. In
I am trying to establish a https connection in android. I made both http

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.