English 中文(简体)
C# TCP/IP Client having an IO Exception
原标题:

The IO Exception: "Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."

The code has been copied from a tutorial and I m sure that this error has something to do with my own machine. All of my firewalls, ESET and Windows, are off. The clients connect via port 55555.

edit:

Client

    static void Main(string[] args)
    {
        MakeClientCallToServer("test");
        MakeClientCallToServer("test2");
        MakeClientCallToServer("test3");

        // Now send a bunch of messages...
        string msg;
        for (int i = 0; i < 100; i++)
        {
            msg = string.Format(Thread.CurrentThread.CurrentCulture,
            "I ll not be ignored! (round {0})", i);
            ThreadPool.QueueUserWorkItem(new
            WaitCallback(MakeClientCallToServer), msg);
        }
        Console.WriteLine("
 Press any key to continue... ");
        Console.Read();
    }
    static void MakeClientCallToServer(object objMsg)
    {
        string msg = (string)objMsg;
        MyTcpClient client = new MyTcpClient(IPAddress.Loopback, 55555);
        client.ConnectToServer(msg);
    }

Server

    static MyTcpServer server;

    static void Main(string[] args)
    {
        ThreadPool.QueueUserWorkItem(RunServer);
        Console.WriteLine("Press esc to stop the server...");
        ConsoleKeyInfo cki;
        while (true)
        {
            cki = Console.ReadKey();
            if (cki.Key == ConsoleKey.Escape)
            {
                break;
            }
        }
    }

    static void RunServer(object stateInfo)
    {
        //Initiate the server)
        server = new MyTcpServer(IPAddress.Loopback, 55555);
        server.Listen();
    }

I ve already made classes named MyTcpServer and MyTcpClient to handle all of the common connections, threading, etc.

问题回答

you can try using Wireshark to capture the data flow to see what happened.

Any possibility we can see some code?

You re right that the most common reason for this error is something blocking on your machine, so turning off all of that stuff is a great first-step. Since it s still happening though, can you load up Wireshark to see what s going on with your packets?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签