ACR_ServerCommunicator.SocketIo.Initialize C# (CSharp) Method

Initialize() public static method

Initialize the socket subsystem.
public static Initialize ( ACR_ServerCommunicator Script ) : bool
Script ACR_ServerCommunicator Supplies the main script object.
return bool
        public static bool Initialize(ACR_ServerCommunicator Script)
        {
            if (Initialized)
                return true;

            try
            {
                RecvfromDelegate = new RecvfromCallout(OnLowLevelReceive);
                RecvfromDelegateHandle = GCHandle.Alloc(RecvfromDelegate);

                try
                {
                    SetRecvfromCallout(Marshal.GetFunctionPointerForDelegate(RecvfromDelegate));
                }
                catch (Exception e)
                {
                    Script.WriteTimestampedLogEntry(String.Format("SocketIo.Initialize: Exception: {0}", e));
                    RecvfromDelegate = null;
                    RecvfromDelegateHandle.Free();
                    throw;
                }
            }
            catch
            {
                return false;
            }

            Initialized = true;
            return true;
        }

Usage Example

        /// <summary>
        /// Initialize the ServerNetworkManager instance.
        /// </summary>
        /// <param name="WorldManager">Supplies the game world manager to which
        /// the network manager instance is bound.</param>
        /// <param name="LocalServerId">Supplies the server id of the local
        /// server.</param>
        /// <param name="Script">Supplies the main script object.</param>
        public ServerNetworkManager(GameWorldManager WorldManager, int LocalServerId, ACR_ServerCommunicator Script)
        {
            SocketIo.Initialize(Script);

            this.WorldManager  = WorldManager;
            this.LocalServerId = LocalServerId;
        }