Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 09:24

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Help] Socket Exception

Discussion on [Help] Socket Exception within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Mr.Zeko's Avatar
 
elite*gold: 248
Join Date: Jun 2011
Posts: 71
Received Thanks: 53
[Help] Socket Exception

Any one can help me with Socket Exception error

Exception
Code:
System.Net.Sockets.SocketException (0x80004005): An operation was attempted on s
omething that is not a socket
   at System.Net.Sockets.Socket.Select(IList checkRead, IList checkWrite, IList
checkError, Int32 microSeconds)
   at ClassicConquer.Necessaries.ServerSockets.SocketPoll.CheckUp() in d:\Source\ServerSockets\SocketPoll.cs:line 55
SocketPoll
Code:
  public static class SocketPoll
    {
        const int SOCKET_PROCESS_INTERVAL = 20, FD_SETSIZE = 2048;

        public readonly static SafeCollections.SafeList<SecuritySocket> ConnectionPoll = new SafeCollections.SafeList<SecuritySocket>();

        private static ServerSocket[] Sockets;

        public static void Create(string group, params ServerSocket[] _Sockets)
        {
            Sockets = _Sockets;
            var ThreadItem = new ThreadGroup.ThreadItem(SOCKET_PROCESS_INTERVAL, group, CheckUp);
            ThreadItem.Open();
        }

        public static void CheckUp()
        {
            try
            {
                List<Socket> RecSockets = new List<Socket>();
                ///   List<Socket> SendSockets = new List<Socket>();
                //   List<Socket> ErrorSockets = new List<Socket>();
                if (ConnectionPoll.Count > 0 || Sockets.Length > 0)
                {

                    System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                    timer.Start();

                    foreach (var socket in Sockets)
                    {
                        if (socket == null || socket.IsAlive == false)
                            continue;
                        RecSockets.Add(socket.GetConnection);
                    }

                    foreach (var socket in ConnectionPoll.GetValues())
                    {
                        if (socket.Alive)
                        {
                            RecSockets.Add(socket.Connection);
                        }
                    }
                    //  IntPtr[] readmask = null;
                    try
                    {
                        Socket.Select(RecSockets, null, null, 0);
                        //    int test = WindowsAPI.ws2_32.MySocketSelect(FD_SETSIZE, RecSockets, 100, out readmask);
                    }
                    catch (Exception e)
                    {
                        MyConsole.WriteLine(e.ToString());
                        MyConsole.SaveException(e);
                    }

                    foreach (var socket in ConnectionPoll.GetValues())
                    {
                        try
                        {
                            //  if (readmask != null && WindowsAPI.ws2_32.FD_ISSET(readmask, socket.Connection.Handle))

                            if (RecSockets.Contains(socket.Connection))
                                socket.ReceiveBuffer();
                            socket.HandlerBuffer();


                            while (SecuritySocket.TrySend(socket)) ;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }

                    }
                    foreach (var socket in Sockets)
                    {
                        try
                        {
                            if (socket == null)
                                continue;

                            //if (readmask != null && WindowsAPI.ws2_32.FD_ISSET(readmask, socket.GetConnection.Handle))
                            if (RecSockets.Contains(socket.GetConnection))
                                socket.Accept();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    timer.Stop();
                    if (timer.ElapsedMilliseconds > 100)
                    {
                        //Console.WriteLine("stamp -> " + timer.ElapsedMilliseconds); 
                    }


                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
Mr.Zeko is offline  
Old 06/22/2020, 02:06   #2
 
elite*gold: 0
Join Date: Oct 2009
Posts: 768
Received Thanks: 550
What I suspect is happening is a race condition. There are no synchronization methods used when polling the available connections. Although I believe SafeCollections.SafeList does use synchronization it is of no help because the main issue is the array Sockets. The issue is experienced when those steps happen sequentially.

1. CheckUp is being called
2. RecSockets is built from Sockets and ConnectionPoll
3. A socket from either Sockets array or ConnectionPoll list is disconnected/disposed
4. Execution reaches "Socket.Select(RecvSockets)" at which point the Select method will throw an exception because a non-socket handle was provided in the list (because said socket handle had been disposed)

While one could employ certain synchronization methods to make CheckUp thread-safe, it would not be an optimal solution. The better route would be to allow the OS to control all of it (it's more likely that the system code works better because it had to been tested and has been proven to be efficient).
Windows provides asynchronous socket interfaces even for low level but luckily you don't have to dig deep. A proper usage of C#'s BeginAsync and SendAsync use said underlying async APIs and would yield better results than you synchronizing your code would.
-impulse- is offline  
Thanks
5 Users
Reply


Similar Threads Similar Threads
[C++] plz help how to get socket id opening socket!!!!!
01/11/2016 - C/C++ - 2 Replies
i need help :handsdown: :handsdown::handsdown::handsdown:
java.net.socket.exception: Connection reset
06/06/2012 - Minecraft - 4 Replies
Hallo . Ich wollt vorhin auf nen server von nem freund und als miecraft verbinden wollte kam erst die meldung "can't reach server" als ich dann trotzdem auf verbinden gedrückt hab kam die meldung aus der überschrift.Weiß jemand woran das liegt vllt an überlastung oder so ?
the exception unknown software exception
02/04/2012 - Archlord - 4 Replies
Hello all!When i start the game i select europe and after says the exception unknown software exception click ok to terminate the program.PLease help me guys to solve this problem1Have a nice day
OMFG! SOCKET SOCKET SOCKET!
06/29/2006 - Conquer Online 2 - 4 Replies
LUCK! ALL LUCK! CRAZY SOBs! lol ROFFLE COPTER! THERE IS NO TRICK. >:o >:o >:o >:o >:o >:o >:o >:o >:o >:o :eek: :eek: :eek: :eek: :eek: :eek: :eek: :eek: :eek: :eek: All this stupid BS about Sockets is driving me crazy.. If anyone ever found out the TRUE "SECRET" it would not be posted on a PUBLIC forum... lol Silly noobs I know if i knew a socket "trick" i wouldnt share.. it would be bad for business! lol :ops: :ops: sorry i am nauseus :D :bandit:



All times are GMT +1. The time now is 09:25.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.