Example #1
0
        // Creates the server, listens, and closes the server
        public static async Task <IpcAdvertise> CreateServerAndReceiveAdvertisement(string serverAddress)
        {
            var server = new ReverseServer(serverAddress);

            Logger.logger.Log("Waiting for connection");
            using Stream stream = await server.AcceptAsync();

            Logger.logger.Log("Got a connection");
            IpcAdvertise advertise = IpcAdvertise.Parse(stream);

            server.Shutdown();
            return(advertise);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns> (pid, clrInstanceId) </returns>
        public static IpcAdvertise Parse(Stream stream)
        {
            var binaryReader = new BinaryReader(stream);
            var advertise    = new IpcAdvertise()
            {
                Magic = binaryReader.ReadBytes(Magic_V1.Length),
                RuntimeInstanceCookie = new Guid(binaryReader.ReadBytes(16)),
                ProcessId             = binaryReader.ReadUInt64(),
                Unused = binaryReader.ReadUInt16()
            };

            for (int i = 0; i < Magic_V1.Length; i++)
            {
                if (advertise.Magic[i] != Magic_V1[i])
                {
                    throw new Exception("Invalid advertise message from client connection");
                }
            }

            // FUTURE: switch on incoming magic and change if version ever increments
            return(advertise);
        }