Socket Exception: An invalid argument was supplied Error Code 10022

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danishashfaq
    New Member
    • May 2010
    • 1

    Socket Exception: An invalid argument was supplied Error Code 10022

    This code works fine on my XP machine, but when I run it on another XP machine it gives error "An invalid argument was supplied." on Socket.IOContro l method. All machines have wireless connection. Also I already test by commenting and uncommenting Socket.SetSocke tOption line.

    I spend lot of time for any web help(including this forum) regarding this type of error but failed to find any solution.

    Can anyone solve this problem?

    Code:
    Socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Raw, System.Net.Sockets.ProtocolType.IP);
    try
    {
    
        Socket.Bind(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(SelectIP.Text), 0));
        Socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.IP, System.Net.Sockets.SocketOptionName.HeaderIncluded, true);
        byte[] optionInValue = { 1, 0, 0, 0 };
        Socket.IOControl(IOControlCode.ReceiveAll, optionInValue, new byte[] { 1, 0, 0, 0 });
        while (btnStop.Enabled)
        {
            System.IAsyncResult ar = Socket.BeginReceive(PacketBuffer, 0, PacketBufferSize, System.Net.Sockets.SocketFlags.None, new System.AsyncCallback(CallReceive), this);
            while (Socket.Available == 0)
            {
                System.Threading.Thread.Sleep(1);
                if (!btnStop.Enabled) break;
            }
            if (!btnStop.Enabled) break;
            int Size = Socket.EndReceive(ar);
            if (!LooseQueue.Checked) ExtractBuffer();
        }
    
    }
    Last edited by Niheel; May 21 '10, 07:04 AM. Reason: moved explanation to the top
Working...