Exemplo n.º 1
0
        private void OnMessage(IAsyncResult ar)
        {
            //Get data
            int count = sock.EndReceive(ar);

            //Get opcode
            NetIQOpcode op = (NetIQOpcode)BitConverter.ToUInt16(buffer, 0);

            //Handle
            switch (op)
            {
            case NetIQOpcode.SERVER_INFO:
                var cmd = new NetIQCommandServerInfo(buffer);
                OnSampleRateChanged?.Invoke(this, cmd.SampleRate);
                break;
            }

            //Listen
            sock.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, OnMessage, null);
        }
Exemplo n.º 2
0
        private void OnClientCommand(NetIQServerClient ctx, byte[] data, int len)
        {
            //Get opcode
            NetIQOpcode op = (NetIQOpcode)BitConverter.ToUInt16(data, 0);

            //Switch
            switch (op)
            {
            case NetIQOpcode.OPEN_STREAM:
                //Decode command
                NetIQCommandOpenStream cmd = new NetIQCommandOpenStream(data);

                //Get endpoint to send to
                IPAddress  addr = ((IPEndPoint)ctx.sock.RemoteEndPoint).Address;
                IPEndPoint ep   = new IPEndPoint(addr, cmd.StreamPort);

                //Make stream
                NetIQServerStream stream = new NetIQServerStream(ep, cmd.BufferSize, cmd.SampleFormat);

                //Apply to list
                lock (streams)
                {
                    //Remove existing stream, if any
                    if (ctx.stream != null)
                    {
                        streams.Remove(ctx.stream);
                    }

                    //Add
                    streams.Add(stream);
                    ctx.stream = stream;
                }
                break;

            default:
                throw new Exception("Unknown opcode!");
            }
        }