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 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

Related Questions

I am running simulation code that is largely bound by CPU speed. I am
I did a behavioral simulation of my code, and it works perfectly. The results
In a c# program for simulating a lan messenger, i have a callback function
have written a stochastic simulation in Java, which loads data from a few CSV
A simulation program I'm using requires a text based input file. I need to
I have in simulation.jsp the following code, by which I receive some simulation data
After running a SPICE simulation I get an .a2d file which I am parsing
I've programmed a simulation, which solves a few equations and draws the result in
In a simulation server environment where users are allowed to submit their own code
I am writing some simulation code and managed to get my model running as

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.