Jump to content
  • Advertisement
Sign in to follow this  
Afr0m@n

C# - using object variables

This topic is 4589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how to access the "original" members and/or functions of an object variable (not an Object variable) in C#? The reason I must know is because I'm using an IOCP library for C#, and when I dispatch objects, like sockets for example, they are returned as object variables to the different threads that are listening to the IOCP. The problem I'm having is that I can't access the methods and functions of a Socket type by way of an object variable, meaning that I can't write to a client unless I figure out how to access the Socket functions and members by way of an object variable. Example ======= BeginAccept() callback function that dispatches a socket to the IOCP:
        private void AcceptCallback(IAsyncResult ar)
        {
            Socket Listener = (Socket)ar.AsyncState;
            Socket Handler = Listener.EndAccept(ar);
            MIOCP.Dispatch(Handler);
        }
HandleIOCPData() function that is run by the IOCP worker threads:
        public void HandleIOCPData()
        {
            //This is the minimum code that should be in here.
            IOCPHandle hIOCP = MIOCP.Register();
            while (true)
            {
                try
                {
                    object obj = hIOCP.Wait();
                    // Process the object
                }
                catch (ManagedIOCPException e)
                {
                    break;
                }
                catch (Exception e)
                {
                    break;
                }
            }
        }
¨ As you can see, the dispatched socket is returned as an object variable. I need to know how to treat the object as a socket. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Thanks!

Didn't realize you could cast it like that!

I tried doing it like:

(Socket)obj.BeginSend()


which obviously didn't work!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
((Socket)obj).Blah() will work. The . is evaluated before the cast.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!