Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So when I run the code below I get the following error appear on the console. This only happens in Windows XP and not Windows 7 regardless of Target framework (2 or 3.5). Any help would be great as I am not familiar with dealing with Win sockets

"The I/O operation has been aborted because of either a thread exit or an application request, error code 995"

which responds to msdn: WSA_OPERATION_ABORTED 995 Overlapped operation aborted. An overlapped operation was canceled due to the closure of the socket, or the execution of the SIO_FLUSH command in WSAIoctl.

C#
     public class SocketPacket
    {
        public System.Net.Sockets.Socket thisSocket;
        public byte[] dataBuffer = new byte[64];
    }


    /// <summary>
    /// receiving data
    /// </summary>
    byte[] concat = new byte[0];
    public void OnDataReceived(IAsyncResult asyn)
    {

        try
        {
            Console.Write("-");
            i = i + 64;
            byte[] src = { 0xAA, 0x55 };
            SocketPacket theSockId = (SocketPacket)asyn.AsyncState;
            int iRx = theSockId.thisSocket.EndReceive(asyn);
            Array.Resize(ref concat, i);

            Array.Copy(theSockId.dataBuffer, 0, concat, concat.Length - 64,64);

            int result = BytePharse.ByteSearch(theSockId.dataBuffer, src, 0);

            if (result != -1)
            {
                Console.WriteLine("\nCompleted, Press Enter to Exit...");
                BytePharse.pharseData(concat);
                Program.ev.Set();
            }

            int duzina = concat.Length;
            WaitForData();
        }
        catch (SocketException se)
        {
            Console.WriteLine(se.Message + "," + se.ErrorCode.ToString());
        }
    }
}
Posted
Comments
TRK3 4-Jan-12 19:56pm    
The problem might be in another part of the program or on the sending end.

The code you give here doesn't include how you are handling exiting the program (on this end or the other end).

Is the sending program exiting after sending the data? It could very well be that the two OS's handle cleaning up sockets differently on program termination. Or you might have a race condition where your Win7 machine processes the received packet before the sender finishes exiting, but it happens the other way around on XP.

On the receiver side, how are you terminating the program? Is there some XP / Win7 difference in whatever you are doing in the original thread to decide when to exit?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900