Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Server program error: Unable to read data from the transport connection

Server program error: Unable to read data from the transport connection

Scheduled Pinned Locked Moved C#
helpsysadmin
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aei_totten
    wrote on last edited by
    #1

    OKay, so I am writing a server program that connects many clients and sends them out data. The problem is that when a client disconnects, when trying to read from another client I get the error.."Unable to read data from the transport connection: An established connection was aborted by the software in your host machine." I have the connections saved in a Dictionary

    private Dictionary<TcpClient, string> Connections = new Dictionary<TcpClient, string>();
    //to add a client
    Connections.Add(tcpClient, currUser);
    // to remove a client
    Connections.Remove(tcpUser);

    //server just loops (in a separate thread for each connection)
    string message = srReceiver.ReadLine();

    //client code

    // setting up connection
    tcpServer = new TcpClient();
    tcpServer.Connect(IPAddress.Parse(ipaddress), port);
    swSender = new StreamWriter(tcpServer.GetStream());

    // sending stuff
    swSender.WriteLine("Whatever");
    swSender.Flush();

    // closing connection
    swSender.WriteLine("Close");
    swSender.Flush();
    swSender.Close();
    tcpServer.Close();

    A 1 Reply Last reply
    0
    • A aei_totten

      OKay, so I am writing a server program that connects many clients and sends them out data. The problem is that when a client disconnects, when trying to read from another client I get the error.."Unable to read data from the transport connection: An established connection was aborted by the software in your host machine." I have the connections saved in a Dictionary

      private Dictionary<TcpClient, string> Connections = new Dictionary<TcpClient, string>();
      //to add a client
      Connections.Add(tcpClient, currUser);
      // to remove a client
      Connections.Remove(tcpUser);

      //server just loops (in a separate thread for each connection)
      string message = srReceiver.ReadLine();

      //client code

      // setting up connection
      tcpServer = new TcpClient();
      tcpServer.Connect(IPAddress.Parse(ipaddress), port);
      swSender = new StreamWriter(tcpServer.GetStream());

      // sending stuff
      swSender.WriteLine("Whatever");
      swSender.Flush();

      // closing connection
      swSender.WriteLine("Close");
      swSender.Flush();
      swSender.Close();
      tcpServer.Close();

      A Offline
      A Offline
      aei_totten
      wrote on last edited by
      #2

      I wanted to add that the dictionary looks fine after the user has been removed. And this works fine as long as everyone stays connected

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups