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

  • Home
  • SEARCH
  • 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 161309
In Process

The Archive Base Latest Questions

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

In simulation of a lan-messenger in c# I am using the loopback address just

  • 0

In simulation of a lan-messenger in c# I am using the loopback address just for starters to check the functionality of the code.However after sending a few messages, I am getting a socket exception while using the end-connect method and then a socket exception while sending the data. Is there any reason behind this exception.

    private void button1_Click(object sender, EventArgs e)     {          HideCaret(this.textBox1.Handle);         StringBuilder sb = new StringBuilder(this.textBox1.Text);         str = this.textBox2.Text;         Socket newsock = new Socket(AddressFamily.InterNetwork,socketType.Stream,   ProtocolType.Tcp);         IPEndPoint ip = new IPEndPoint(localaddress, 5555);         newsock.BeginConnect(ip, new AsyncCallback(connected), newsock);         if (str != '')         {             sb.AppendLine(this.textBox2.Text);             this.textBox1.Text = sb.ToString();             this.textBox2.Text = '\0';             send = Encoding.ASCII.GetBytes(str);             try             {                 newsock.BeginSend(send, 0, send.Length, SocketFlags.None, new AsyncCallback(sent), newsock);             }             catch (ArgumentException)             {                 MessageBox.Show('arguments incorrect in begin-send call', 'Error', MessageBoxButtons.OK);             }             catch (SocketException)             {                 MessageBox.Show('error in accessing socket while sending', 'Error', MessageBoxButtons.OK);             }             catch (ObjectDisposedException)             {                 MessageBox.Show('socket closed while sending', 'Error', MessageBoxButtons.OK);             }             catch (Exception)             {                 MessageBox.Show('error while sending', 'Error', MessageBoxButtons.OK);             }          }                                       } 

Please help

  • 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. 2026-05-11T11:11:26+00:00Added an answer on May 11, 2026 at 11:11 am

    It’s possibly because you’re not waiting for the socket to be connected before sending data. You have two options:

    1. Send the data asynchronously from your connected callback method.
    2. Send the data synchronously by blocking this thread until connected.

    You accomplish #1 by combining the data to send and the socket into a new class, then passing that as state in your call to BeginConnect. Then move your send code to the callback method.

    You accomplish #2 by setting up a System.Threading.ManualResetEvent and calling WaitOne after BeginConnect. Then call EndConnect in your connected callback method, followed by a Set on your ManualResetEvent. Then proceed to send as you have above.


    You’ll also probably learn more if you find out what kind of SocketException you’re getting.

    From the MSDN Documentation:

    If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

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

Sidebar

Ask A Question

Stats

  • Questions 240k
  • Answers 240k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer iBatis uses JavaBean naming conventions, and "xx.xx" isn't a valid… May 13, 2026 at 7:17 am
  • Editorial Team
    Editorial Team added an answer You can try something like this DECLARE @Table TABLE( Val… May 13, 2026 at 7:17 am
  • Editorial Team
    Editorial Team added an answer It is an NSString but you are using it elsewhere… May 13, 2026 at 7:17 am

Related Questions

Firstly, I'm new to the specifics of IPv6 so I wouldn't be surprised if
This is not yet particularly programing related but, I am very interested in how
I have a very limited experience of database programming and my applications that access
i have tested the difference between defining varchar(max) in opposite text with our legacy

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.