Author Topic: C# Exception: "Unable to write data to the transport connection:"  (Read 123 times)

0 Members and 1 Guest are viewing this topic.

Offline Rocket50

  • ******
  • Posts: 2732
  • Gender: Male
  • My god it's dusty
  • Respect: +946
C# Exception: "Unable to write data to the transport connection:"
« on: September 11, 2012, 06:15:33 PM »
0
Full Exception:

Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.



static void Connection(string add, int port, string input)
    {   
             if (input == "connect")
             {
             
                   
       
                Byte[] data = System.Text.Encoding.ASCII.GetBytes(input);     
                TcpClient client = new TcpClient();
                client.Connect(add,port); //Initial Connection works
                if (client.Connected == true)
                {
                    Console.WriteLine("\nConnected to {0} via port: {1}!", add, port);
               
                    NetworkStream network = client.GetStream();
                    network.Write(data, 0, data.Length);

                connecttest:

                    Console.Write("\nEnter a message: ");
                    message = Console.ReadLine();
               
                    if (message != "")
                    {
                        data = System.Text.Encoding.ASCII.GetBytes(message);
                        network.Write(data, 0, data.Length); //Error happens here

                    }
                    if (client.Connected == false)
                    {
                        Console.WriteLine("Client Forcefully Disconnected :<");
                        Main();
                    }
                    else
                    {
                        Console.WriteLine("\nSent!"); //Successful second sending of data, but third causes error
                    }
                    if (message == "disconnect")
                    {
                        client.Close();
                        if (client.Connected == false)
                        {
                            Console.WriteLine("\nClient Disconnected\n");

                        }
                        Main();
                    }
                    else
                    {
                        goto connecttest;
                    }
                   


Stuff I tried:

Turning off router firewalls
Turning off Anti Virus
Turning off windows Firewall
Tried on another computer

any help would be really appreciated... Except google. I've tried that too...

Foofoo.
« Last Edit: September 11, 2012, 06:20:12 PM by Rocket50 »

Offline coolzeldad

  • ******
  • OwnerDonatorOld Forum MemberrNd DeveloperLinux UserWindows UserDog LoverLeague PlayerDWO Player
    View More Badges!

  • Posts: 3333
  • I eat ddos for breakfast OMNOMONOM
  • Respect: +2711
    • .:`=-~rANdOm~`-=:. Game Servers
Re: C# Exception: "Unable to write data to the transport connection:"
« Reply #1 on: September 14, 2012, 01:11:14 AM »
+1
Just looked at this, try verifying when you lose the connection - or at least a close approximation.

Monitor when the value of client.Connected changes... after you write data to the stream and when you jump to your connecttest label (which i do not recommend the use of), etc.
 ▲
▲▲Big thanks to Marie for this awesome sprite! :3

Spoiler: Moar Imagez (click to show/hide)
pingaz
Thanks Cryptokid!

Thanks gamefreak!


-- My youtube: http://www.youtube.com/coolzeldad
-- My deviantart: http://coolzeldad.deviantart.com
-- My soundcloud: http://www.soundcloud.com/coolzeldad
-- My ustream: http://www.ustream.tv/channel/coolzeldapingaz
-- My twitchtv: http://www.twitch.tv/coolzeldad

-- rNd Wiki: http://wiki.randomgs.com
-- rNd Youtube: http://www.youtube.com/RandomgsProductions
-- rNd Steam Group: http://steamcommunity.com/groups/r_A_N_d_O_m

Spoiler: rNd Typography (click to show/hide)





Every time you download Garry's Mod illegally, Garry makes a bug.

When people ask me "Plz" because its shorter than "Please" I feel perfectly justified to answer "No" because its shorter than "Yes".

derp herp lerp perp kerp serp zerp - say faiv timez fazt


Offline Rocket50

  • ******
  • Posts: 2732
  • Gender: Male
  • My god it's dusty
  • Respect: +946
Re: C# Exception: "Unable to write data to the transport connection:"
« Reply #2 on: September 15, 2012, 09:44:00 PM »
0
I created a simpler version of this solely to test it, and what it does is it establishes, and sends "a" across the stream immediately. Then I test the connection as of the instance "a" was sent, (design choice by Microsoft to only allow .Connected's value to change as of the last instance something was sent), and then I send a user input string, which is sent. However the third one does not.

Offline Foofoojack

  • ******
  • Posts: 2604
  • Gender: Male
  • Ộ_Ộ
  • Respect: +546
Re: C# Exception: "Unable to write data to the transport connection:"
« Reply #3 on: September 15, 2012, 10:30:56 PM »
+1
try goog- *User was banned for this post*




« Last Edit: September 15, 2012, 10:30:56 AM by yamada »