Exemple #1
0
        protected void UpdateAudioStream(StreamedPacket packet)
        {
            //ok we found the chunk we're looking for lets process it and fire off any others we also may need to.
            lock (Lock)
            {
                mSyncStream.Position = mSyncStreamLastWrittenPos;
                StreamingHelper.CopyStream(packet.stream, mSyncStream);
                mSyncStreamLastWrittenPos = mSyncStream.Position;
                mIncommingStream          = !packet.endOfStream;

                if (mIncommingStream == false)
                {
                    mLogMessage("Finished Receiving Media File\r\n");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// The constructor for this.  In addition to initializing all of the parameters it attempts to open and connect
        /// to the network.  This is done asynchronously with ProcessOpen being called either after a timeout (hard coded to 1 minute)
        /// or when a response is received.
        /// </summary>
        /// <param name="nodeName">the unique nodename</param>
        /// <param name="networkName">the name of the network</param>
        /// <param name="password">the password for the network</param>
        public bool PeerChannelWrapperStart(String nodeName, String networkName, String password)
        {
            CheckDisposed();
            //////////////////////////////////////////////////////////////////////////
            //Initialize all the parameters...
            //////////////////////////////////////////////////////////////////////////
            mNodeName    = nodeName;
            mNetworkName = networkName;

            //password cannot be empty otherwise mFactory.CreateChannel() below will throw an exception
            if (string.IsNullOrEmpty(password))
            {
                mPassword = "******";
            }
            else
            {
                mPassword = password.Trim();
            }

            //Construct InstanceContext to handle messages on callback interface.
            mInstanceContext = new InstanceContext(this);

            //////////////////////////////////////////////////////////////////////////
            //Create the PeerTcpBinding
            //////////////////////////////////////////////////////////////////////////
            NetPeerTcpBinding p2pBinding = new NetPeerTcpBinding();

            p2pBinding.Name = "BindingDefault";
            p2pBinding.Port = 0;                                       //dynamic port
            p2pBinding.MaxReceivedMessageSize = 70000000;              //set the max message size in bytes (70mb)
            p2pBinding.Resolver.Mode          = PeerResolverMode.Pnrp; //use the standard pnrp for our resolver to find the network

            //////////////////////////////////////////////////////////////////////////
            //create the Endpoint Address and Service Endpoint.
            //////////////////////////////////////////////////////////////////////////
            String          bindingInfo     = "net.p2p://"; //the endpoint address for a NetPeerTcpBinding must start with net.p2p
            EndpointAddress epa             = new EndpointAddress(String.Concat(bindingInfo, mNetworkName));
            ServiceEndpoint serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IPeerChannel)), p2pBinding, epa);

            //////////////////////////////////////////////////////////////////////////
            // Create the participant with the given endpoint configuration
            // Each participant opens a duplex channel to the mesh
            // participant is an instance of the channel to the mesh
            //////////////////////////////////////////////////////////////////////////
            mFactory = new DuplexChannelFactory <IPeerChannelWrapper>(mInstanceContext, serviceEndpoint);
            mFactory.Credentials.Peer.MeshPassword = mPassword;
            mParticipant = mFactory.CreateChannel();

            mPicture = new PictureHelper(mParticipant.SharePicture, mNodeName);
            mTextPeerChannelHelper = new ChatHelper(mParticipant.ShareTextMessage);
            mFilePeerChannelHelper = new FileHelper(mParticipant.ShareFile);
            mStreamedAudio         = new StreamingHelper(mParticipant, mNodeName, mParticipant.ShareStreamedAudio);
            mStreamedVideo         = new StreamingHelper(mParticipant, mNodeName, mParticipant.ShareStreamedVideo);

            //////////////////////////////////////////////////////////////////////////
            //Start an asynchronous call that will try to open a connection to the network.
            //if one is not found, but the pnrp resolver is running then a new network will be
            //created.
            //////////////////////////////////////////////////////////////////////////
            try
            {
                AsyncCallback callBack = new AsyncCallback(ProcessOpen);
                TimeSpan      ts       = new TimeSpan(0, 1, 0); //wait a minute
                mParticipant.BeginOpen(ts, callBack, this);
            }
            catch (CommunicationException e)
            {
                System.Windows.MessageBox.Show(String.Format("Error while joining the network: {0}", e.Message));
                mParticipant = null;
                return(false);
            }
            return(true);
        }