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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:48:35+00:00 2026-06-12T20:48:35+00:00

I am developing an app, in which c sharp server communicates with android client.

  • 0

I am developing an app, in which c sharp server communicates with android client.
Server needs to send multiple message to the Android tcpClient. As to send message I have to close the tcpClient Object on the server. otherwise it does not send. Once tcpClient is closed how can i communicate with my client again , how can i keep track and send multiple messages, once i close tcpClient, or there is any other way of sending without closing it.
If the question is still unclear, please comment below

it sends one message easlity but i need to send more messages from time to time

Here is the snippet of code for server

//in a thread
void receivingMessages(object param)
    {
        try
        {
            var paramArray = (object[])param;
            var id = paramArray[0];
            var client = paramArray[1] as TcpClient;

            var stream = client.GetStream();

            while (true)
            {
                byte[] buffer = new byte[2048];
                int bytesRead = stream.Read(buffer, 0, 2048);

                if (bytesRead > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    string v = Encoding.ASCII.GetString(buffer);

                    int index = v.IndexOf('\0');
                    string trimmedXml = v.TrimEnd(new char[] { '\0' });

                    var root = XDocument.Parse(trimmedXml).Root;
                    //to get the type of xml like it is login register or message
                    string xmlType = root.Name.ToString();

                    //some checks     
                    string result = " server messages";
                    SendMessage(client, result);

                }

                //Thread.Sleep(10);
            }
        }
        catch (Exception)
        {

        }

    }


    public void SendMessage(TcpClient client, string message)
    {

        byte[] buffer = Encoding.ASCII.GetBytes(message);

        NetworkStream stream = client.GetStream();
        stream.Write(buffer, 0, buffer.Length);

        client.Close();
    }
}
}
  • 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-12T20:48:36+00:00Added an answer on June 12, 2026 at 8:48 pm

    Try this:

    public void SendMessage(TcpClient client, string message)
    {
    
        //byte[] buffer = Encoding.ASCII.GetBytes(message);
    
        NetworkStream stream = client.GetStream();
        StreamWriter writer = new StreamWriter(stream);
        writer.WriteLine(message);
        writer.Flush();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing an app which needs to send authentication data with it to
I am developing a Facebook app. I have a server side OAuth flow which
I am developing an app which listens to incoming sms. I have added the
I am currently developing an app which will be on Android Market. How can
I am developing an app which requires to send email to a person. Everything
Am developing an app which has a calculator function: for example, i have 4
I'm developing a MVC 3 Razor Web App, in which details of multiple categories
Hi I am developing an android app in which if user opens the application
I'm developing an app which needs access to 'the last 5 seconds worth of
I am developing facebook app which needs to retrieve events created by some of

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.