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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:10:49+00:00 2026-05-30T06:10:49+00:00

I am trying to send data from a C#.NET (Windows Application) program to a

  • 0

I am trying to send data from a C#.NET (Windows Application) program to a Java (Android App) program and vice versa, via TCP connection through Wifi. Till now I am success to send data from Java to C#, but unable to do so from C# to Java.

Following is the Java code, I used to create a connection and receive data:

ServerSocket serverSocket = null;
DataInputStream socketInputStream;
while (true) {
        try {
            String localIPAddr = getLocalIPAddress();
            InetSocketAddress ipEndPoint = new InetSocketAddress(
                    InetAddress.getByName(localIPAddr), 8222);
            serverSocket = new ServerSocket();
            serverSocket.bind(ipEndPoint, 4);
            workerSocket = serverSocket.accept();

            socketInputStream = new DataInputStream(
                    workerSocket.getInputStream());
            inputText.setText(socketInputStream.readUTF());
        } catch (Exception ex) {
            throw ex;
        }
    }

Here getLocalIPAddress() method returns the IP Address of the Android Device.

Following is the C# code in Windows Application to connect to the Android’s IP Address (192.168.1.6) and send data to it:

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!clientSocket.Connected)
                    clientSocket.Connect(IPAddress.Parse("192.168.1.6"), 8222);
                clientSocket.Send(Encoding.UTF8.GetBytes(txtInput.Text));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Well, client (C#) is failing to connect to the server (Java) That means data is not leaving from client. But it will, if it get connected. Please tell me what am I missing and where am I mistaken. 🙂

  • 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-30T06:10:50+00:00Added an answer on May 30, 2026 at 6:10 am

    Well, I have solved this myself, but of course Dilberted has helped me a little bit. I thank him for what he has provided. 🙂

    Check out the solved Java code below:

    ServerSocket serverSocket = null;
    Socket workerSocket;
    DataInputStream socketInputStream;
    try {
        if (serverSocket == null) {
            // No need to get local IP address and to bind InetSocketAddress.
            // Following single line make it very simple.
            serverSocket = new ServerSocket(8222, 4);
            workerSocket = serverSocket.accept();
        }
        // When data are accepted socketInputStream will be invoked.
        socketInputStream = new DataInputStream(
                    workerSocket.getInputStream());
    
        /* Since data are accepted as byte, all of them will be collected in the
        following byte array which initialised with accepted data length. */
        byte[] rvdMsgByte = new byte[socketInputStream.available()];
    
        // Collecting data into byte array
        for (int i = 0; i < rvdMsgByte.length; i++)
            rvdMsgByte[i] = socketInputStream.readByte();
    
        // Converting collected data in byte array into String.
        String rvdMsgTxt = new String(rvdMsgByte);
    
        // Setting String to the text view.
        receivedMsg.setText(rvdMsgTxt);
    } catch (Exception ex) {
        throw ex;
    }
    

    Note that a separate thread is to be used to run this code in background.

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

Sidebar

Related Questions

I am currently trying to send some data from and Android application to a
I am trying to send the POST data from java to a PHP page.
I'm trying to send binary data from a database over an ASP.NET page. I
I'm trying to send data from client-side to server-side (asp.net c#), if you really
I'm trying to send data from a form to an external script prior to
I am trying to send some data from a LINQ query in C# to
I am trying to send data to my jsp via:xhr.send(projectCode); but apparently the parameter
We are using C#, ASP.NET & WCF. I am trying to send form data
I'm trying to create a TCP connection and send/read data that uses SSL, but
I'm trying to AES encode data in java, send it over the network and

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.