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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:40:03+00:00 2026-05-24T21:40:03+00:00

Well I’m making a Client-Server application and I can send messages to my client

  • 0

Well I’m making a Client-Server application and I can send messages to my client just fine but when I do it the other way around (Client to server) the server application just closes down, any help on how to fix this?

public void OnDataReceived(IAsyncResult asyn)
    {
        try
        {
            SocketPacket socketData = (SocketPacket)asyn.AsyncState;

            int iRx = 0;
            iRx = socketData.m_currentSocket.EndReceive(asyn);
            char[] chars = new char[iRx + 1];
            System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
            int charLen = d.GetChars(socketData.dataBuffer,
                                     0, iRx, chars, 0);
            System.String szData = new System.String(chars);
            area1.AppendText(szData);


            WaitForData(socketData.m_currentSocket); // Continue the waiting for data on the Socket
        }
        catch (ObjectDisposedException)
        {
            System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
        }
        catch (SocketException se)
        {
            MessageBox.Show(se.Message);
        }
    }

After doing some breakpoints I realized it closes after reaching this part when it tries to append it on the textArea it closes without an error.

Any ideas on how to fix this? I guessing something to do with the threads but not sure why it just closes.

  • 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-24T21:40:04+00:00Added an answer on May 24, 2026 at 9:40 pm

    Does an exception happen when AppendText is called? If yes, can you include the call stack? Is szData valid data when AppendText is called? Try putting a try/catch around the code to get the exception information:

    try
    {
        ... your code...
    }
    catch (Exception e)
    {
        ... examine 'e' in the debugger or dump it to a log file
    }
    

    One thing that might be going wrong is that you are accessing a UI control from the non-UI thread, but it could be other things. It’s hard to tell from the code snippet you posted.

    Updated:
    If the exception was that the control is being invoked from the wrong thread, you can try adding a function like this, then calling that instead of accessing the control directly (untested):

        private void AppendText(string text)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.area1.InvokeRequired)
            {   
                SetTextCallback d = new AppendTextCallback(AppendText);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                this.area1.AppendText(text);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, it seems simple enough, but I can't find a way to add a
Well this kind of n00b question but I still can't figure it out. I
Well, I just started to work on server side scripting , I chose PHP,
Well if i want to store data for a application machine wide i just
Well... simple question, right? But with no so simple answers. In firefox i use
well i have this messages table with sample values like these: msg_id recipient_id read
Well my windows service has to send out automated emails when the sql database
Well I'm making an program about payrolls and I'm stuck. In the program, after
Well, I am new to Delphi and really offline programming in general (other than
Well, this must be a silly one. Here below is a can-not-be-simpler code in

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.