当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.Close方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.Close方法的具体用法?C# NamedPipeServerStream.Close怎么用?C# NamedPipeServerStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartInternal

        private async void StartInternal(CancellationToken cancellationToken)
        {
            byte[] buffer = new byte[256];
            var commandBuilder = new StringBuilder();

            var serverStream = new NamedPipeServerStream(this.PipeName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 0, 0);

            using (cancellationToken.Register(() => serverStream.Close()))
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    await Task.Factory.FromAsync(serverStream.BeginWaitForConnection, serverStream.EndWaitForConnection, TaskCreationOptions.None);

                    int read = await serverStream.ReadAsync(buffer, 0, buffer.Length);
                    commandBuilder.Append(Encoding.ASCII.GetString(buffer, 0, read));

                    while (!serverStream.IsMessageComplete)
                    {
                        read = serverStream.Read(buffer, 0, buffer.Length);
                        commandBuilder.Append(Encoding.ASCII.GetString(buffer, 0, read));
                    }

                    var response = this.HandleReceivedCommand(commandBuilder.ToString());
                    var responseBytes = Encoding.ASCII.GetBytes(response);
                    serverStream.Write(responseBytes, 0, responseBytes.Length);

                    serverStream.WaitForPipeDrain();
                    serverStream.Disconnect();

                    commandBuilder.Clear();
                }
            }
        }
开发者ID:RipleyBooya,项目名称:SyncTrayzor,代码行数:33,代码来源:IpcCommsServer.cs

示例2: UserSignIn

        private void UserSignIn(string username, string password)
        {
            string hashed_password = sha256(password);
            MessageBox.Show(hashed_password);
            //send username and password to python and checks if correct
            string info = username + "#" + hashed_password;
            // Open the named pipe.

            var server = new NamedPipeServerStream("Communicate");
            server.WaitForConnection();     
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(server); 
            send(bw, info);
            string message = recv(br); 
            server.Close();
            server.Dispose();

            //if receives true then send the user to the next gui.
            if (message == "1")
            {
                
                SaveFile form = new SaveFile();
                form.Show();

            }
            else
            {
                
                MessageBox.Show("incorrect password or username");
                this.Show();
            }
            
            
        }
开发者ID:Coby-Sonn,项目名称:coby-s-project,代码行数:34,代码来源:Form1.cs

示例3: UserSignIn

        private void UserSignIn(string username, string password)
        {
            if (username == "")
            {
                MessageBox.Show("Please enter username");
                this.Show();
            }
            else if(password == "")
            {
                MessageBox.Show("Please enter password");
                this.Show();
            }
            else
            {

                string hashed_password = sha256(password);
                //send username and password to python and checks if correct
                string info = "login#" + username + "#" + hashed_password;
                // Open the named pipe.

                var server = new NamedPipeServerStream("Communicate");
                server.WaitForConnection();     
                var br = new BinaryReader(server);
                var bw = new BinaryWriter(server); 
                send(bw, info);
                string message_to_split = recv(br);
                message_to_split = message_to_split + recv(br);
                string message = message_to_split.Split('#')[0];
                if (message_to_split.Split('#')[1] != "0")
                {
                    this.my_uid = message_to_split.Split('#')[2];
                    this.firstname = message_to_split.Split('#')[1];
                    this.lastname = message_to_split.Split('#')[3];
                    MessageBox.Show(my_uid + firstname + lastname);
                }
                server.Close();
                server.Dispose();
                
                //if receives true then send the user to the next gui.
                if (message == "Signed in")
                {
                    string user_info = this.my_uid + "#" + this.firstname + "#" + this.lastname;
                    SaveFile form = new SaveFile(user_info);
                    form.Show();
                }
                else
                {
                
                    MessageBox.Show("incorrect password or username");
                    this.Show();
                }
            
            
            
            }
        }
开发者ID:Coby-Sonn,项目名称:coby-s-project,代码行数:56,代码来源:Form1.cs

示例4: PipeThread

        void PipeThread()
        {
            NamedPipeServerStream pipeServer = null;
            try
            {
                pipeServer = new NamedPipeServerStream("NowPlayingtunesSongPipe", PipeDirection.InOut);
                pipeServer.WaitForConnection();
                //When Connected
                StreamString stream = new StreamString(pipeServer);
                String playerStr = stream.ReadString();
                Debug.WriteLine("[foobar2000]Song changed.");
                Debug.WriteLine(playerStr);
                Debug.WriteLine("[foobar2000]dump end.");
                String[] playerStrSplit = playerStr.Split('\n');
                Core.iTunesClass song = new Core.iTunesClass();
                song.AlbumArtworkEnabled = false;
                song.SongTitle = playerStrSplit[0];
                song.SongAlbum = playerStrSplit[1];
                song.SongArtist = playerStrSplit[2];
                song.SongAlbumArtist = playerStrSplit[3];
                song.isFoobar = true;
                try
                {
                    song.SongTrackNumber = int.Parse(playerStrSplit[4]);
                }
                catch (Exception ex2)
                {
                }
                song.SongGenre = playerStrSplit[5];
                song.SongComposer = playerStrSplit[6];

                pipeServer.Close();
                pipeServer.Dispose();
                //適当にイベント発生させる
                onSongChangedEvent(song);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("[foobar2000] ERROR");
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                if (pipeServer != null)
                {
                    if (pipeServer.IsConnected)
                    {
                        pipeServer.Dispose();
                    }
                }
            }
            //Remake thread
            StartThread();
        }
开发者ID:kazukioishi,项目名称:NowplayingTunes,代码行数:54,代码来源:ExternalPlayerPipe.cs

示例5: Run

        internal void Run()
        {
            // Create pipe instance
            using (var pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4))
            {
                Console.WriteLine("[SJPS] Thread created");
                // wait for connection
                Console.WriteLine("[SJPS] Waiting for connection");
                pipeServer.WaitForConnection();
                Console.WriteLine("[SJPS] Client has connected");
                IsRunning = true;
                pipeServer.ReadTimeout = 1000;

                // Stream for the request.
                var sr = new StreamReader(pipeServer);
                // Stream for the response.
                var sw = new StreamWriter(pipeServer) {AutoFlush = true};

                while (IsRunning)
                {
                    try
                    {
                        // Read request from the stream.
                        var echo = sr.ReadLine();
                        Console.WriteLine("[SJPS] Recieved request: " + echo);

                        if (echo == "Close")
                        {
                            IsRunning = false;
                            break;
                        }

                        try
                        {
                            ParseRequest(echo);
                            sw.WriteLine("Ack");
                        }
                        catch (Exception)
                        {
                            sw.WriteLine("Error");
                        }
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("[SJPS] Error: {0}", e.Message);
                        IsRunning = false;
                    }
                }

                pipeServer.Disconnect();
                pipeServer.Close();
            }
        }
开发者ID:OronDF343,项目名称:Sky-Jukebox,代码行数:53,代码来源:PipeServer.cs

示例6: ConnectToService

        /// <summary>
        /// Connect from core to the service - used in core to listen for commands from the service
        /// </summary>
        public static void ConnectToService()
        {
            if (connected) return; //only one connection...

            Async.Queue("MBService Connection", () =>
            {
                using (NamedPipeServerStream pipe = new NamedPipeServerStream(MBSERVICE_OUT_PIPE,PipeDirection.In))
                {
                    connected = true;
                    bool process = true;
                    while (process)
                    {
                        pipe.WaitForConnection(); //wait for the service to tell us something
                        try
                        {
                            // Read the request from the service.
                            StreamReader sr = new StreamReader(pipe);

                            string command = sr.ReadLine();
                            switch (command.ToLower())
                            {
                                case IPCCommands.ReloadItems:
                                    //refresh just finished, we need to re-load everything
                                    Logger.ReportInfo("Re-loading due to request from service.");
                                    Application.CurrentInstance.ReLoad();
                                    break;
                                case IPCCommands.Shutdown:
                                    //close MB
                                    Logger.ReportInfo("Shutting down due to request from service.");
                                    Application.CurrentInstance.Close();
                                    break;
                                case IPCCommands.CloseConnection:
                                    //exit this connection
                                    Logger.ReportInfo("Service requested we stop listening.");
                                    process = false;
                                    break;

                            }
                            pipe.Disconnect();
                        }
                        catch (IOException e)
                        {
                            Logger.ReportException("Error in MBService connection", e);
                        }
                    }
                    pipe.Close();
                    connected = false;
                }
            });
        }
开发者ID:bartonnen,项目名称:MediaBrowser.Classic,代码行数:53,代码来源:MBServiceController.cs

示例7: Main

        static void Main(string[] args)
        {
            Console.Title = "Log - Trinix";

            if (!Directory.Exists("Logs"))
                Directory.CreateDirectory("Logs");

            Parser parser = null;
            while (true)
            {
                NamedPipeServerStream pipeServer = new NamedPipeServerStream("trinix");
                pipeServer.WaitForConnection();

                if (parser != null)
                    parser.Dispose();

              //  MemoryStream ms = new MemoryStream();
                //parser = new Parser();
               // parser.Parse(ms);
                StreamWriter log = new StreamWriter("Logs\\" + String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now) + ".log");

                try
                {
                    while (pipeServer.IsConnected)
                    {
                        int v = pipeServer.ReadByte();

                        if (v == -1)
                            break;

                       // ms.WriteByte((byte)v);
                        Console.Write((char)v);
                        log.Write((char)v);
                    }

                    pipeServer.Close();
                    log.Close();
                }
                catch
                {
                }

                Console.Write(Environment.NewLine);
                Console.WriteLine("----------- Connection ended -----------");
                Console.Write(Environment.NewLine);
            }
        }
开发者ID:jamonahn,项目名称:Trinix,代码行数:47,代码来源:Program.cs

示例8: Start

    // Use this for initialization
    void Start()
    {
        Debug.Log("Starting Server");
        server = new NamedPipeServerStream("NPtest");

        //Console.WriteLine("Waiting for connection...");
        Debug.Log("Waiting for connection...");
        server.WaitForConnection();

        //Console.WriteLine("Connected.");
        Debug.Log("Connected.");

        br = new BinaryReader(server);
        bw = new BinaryWriter(server);

        while (true)
        {
            try
            {
                var len = (int)br.ReadUInt32();            // Read string length
                var str = new string(br.ReadChars(len));    // Read string

                //Console.WriteLine("Read: \"{0}\"", str);
                Debug.Log(String.Format("Read: {0}", str));
                str = new string(str.Reverse().ToArray());  // Just for fun

                var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array     
                bw.Write((uint)buf.Length);                // Write string length
                bw.Write(buf);                              // Write string
                //Console.WriteLine("Wrote: \"{0}\"", str);
                Debug.Log(String.Format("Wrote: {0}", str));
            }
            catch (EndOfStreamException)
            {
                break;                    // When client disconnects
            }
        }

        //Console.WriteLine("Client disconnected.");
        Debug.Log("Client disconnected.");
        server.Close();
        server.Dispose();


    }
开发者ID:ma581,项目名称:TestingPipes,代码行数:46,代码来源:PipeWork.cs

示例9: ThreadStartServer

 public void ThreadStartServer()
 {
     //FileStream fs = new FileStream("c:\\1\\server.txt", FileMode.Create,FileAccess.ReadWrite);            
   //  StreamWriter sw = new StreamWriter(fs);
  //   sw.AutoFlush = true;
     
     while (true)
     {
         NamedPipeServerStream pipeStream = new NamedPipeServerStream(pipeName,PipeDirection.InOut,1);
         //sw.WriteLine("NamedPipeServerStream pipeStream = new NamedPipeServerStream(mytestpipe,PipeDirection.InOut,1);");
         while (true)
         {
             if (G.mainWindow != null) break;
         }                
         pipeStream.WaitForConnection();                
         //sw.WriteLine("pipeStream.WaitForConnection();");
         StreamReader sr = new StreamReader(pipeStream);
         //sw.WriteLine("StreamReader sr = new StreamReader(pipeStream);");
         string temp = sr.ReadLine();
        // sw.WriteLine("string temp = sr.ReadLine();");                
        // sw.WriteLine(temp);
        // sw.WriteLine("//sw.WriteLine(temp);");
         if (temp!=null)
         if (temp.Length!=0)
         {
          //   sw.WriteLine("if (temp != null || temp.Length!=0)");
             G.mainWindow.Dispatcher.Invoke(
                 new Action(
                     delegate()
                     {
                         //if (G.mainWindow == null) MessageBox.Show("Хуй тебе!");
                             G.mainWindow.OpenFile(temp); 
                         }
                         ));
          //   sw.WriteLine("G.mainWindow.Dispatcher.Invoke(new Action(delegate() { G.mainWindow.OpenFile(temp); }));");
         }
         //pipeStream.WaitForPipeDrain();
         pipeStream.Close();
         //sw.WriteLine("pipeStream.Close();");
         pipeStream = null;
         sr.Close();// sr = null;
     //    sw.WriteLine("sr.Close();");
         //sw.Close();
     }   //while
 }
开发者ID:NightmareX1337,项目名称:lfs,代码行数:45,代码来源:ProgramPipeTest.cs

示例10: Main

        static void Main()
        {
            string echo = "";
            while (true)
            {
                //Create pipe instance
                NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4);
                Console.WriteLine("[ECHO DAEMON] NamedPipeServerStream thread created.");

                //wait for connection
                Console.WriteLine("[ECHO DAEMON] Wait for a client to connect");
                pipeServer.WaitForConnection();

                Console.WriteLine("[ECHO DAEMON] Client connected.");
                try
                {
                    // Stream for the request.
                    StreamReader sr = new StreamReader(pipeServer);
                    // Stream for the response.
                    StreamWriter sw = new StreamWriter(pipeServer);
                    sw.AutoFlush = true;

                    // Read request from the stream.
                     echo = sr.ReadLine();

                    Console.WriteLine("[ECHO DAEMON] Request message: " + echo);

                    // Write response to the stream.
                    sw.WriteLine("[ECHO]: " + echo);

                    pipeServer.Disconnect();
                }
                catch (IOException e)
                {
                    Console.WriteLine("[ECHO DAEMON]ERROR: {0}", e.Message);
                }

                System.IO.File.WriteAllText(@"C:\Users\tlewis\Desktop\WriteLines.txt", echo);

                pipeServer.Close();
            }
        }
开发者ID:gw-sd-2016,项目名称:Presenting101,代码行数:43,代码来源:Program.cs

示例11: NoServerConnection

            public async Task NoServerConnection()
            {
                using (var readyMre = new ManualResetEvent(initialState: false))
                using (var doneMre = new ManualResetEvent(initialState: false))
                {
                    var pipeName = Guid.NewGuid().ToString();
                    var mutexName = BuildServerConnection.GetServerMutexName(pipeName);
                    bool created = false;
                    bool connected = false;

                    var thread = new Thread(() =>
                    {
                        using (var mutex = new Mutex(initiallyOwned: true, name: mutexName, createdNew: out created))
                        using (var stream = new NamedPipeServerStream(pipeName))
                        {
                            readyMre.Set();

                            // Get a client connection and then immediately close it.  Don't give any response.
                            stream.WaitForConnection();
                            connected = true;
                            stream.Close();

                            doneMre.WaitOne();
                            mutex.ReleaseMutex();
                        }
                    });

                    // Block until the mutex and named pipe is setup.
                    thread.Start();
                    readyMre.WaitOne();

                    var exitCode = await RunShutdownAsync(pipeName, waitForProcess: false);

                    // Let the fake server exit.
                    doneMre.Set();
                    thread.Join();

                    Assert.Equal(CommonCompiler.Failed, exitCode);
                    Assert.True(connected);
                    Assert.True(created);
                }
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:42,代码来源:VBCSCompilerServerTests.cs

示例12: Main

        static void Main(string[] args)
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("NPtest");

            Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();

            Console.WriteLine("Connected.");
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    var str = new string(br.ReadChars(len));    // Read string

                    Console.WriteLine("Read: \"{0}\"", str);

                    str = new string(str.Reverse().ToArray());  // Just for fun

                    var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array     
                    bw.Write((uint)buf.Length);                // Write string length
                    bw.Write(buf);                              // Write string
                    Console.WriteLine("Wrote: \"{0}\"", str);
                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            Console.WriteLine("Client disconnected.");
            server.Close();
            server.Dispose();



        }
开发者ID:ma581,项目名称:TestingPipes,代码行数:41,代码来源:Program.cs

示例13: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            var  server = new NamedPipeServerStream("NPtest1");
               Console.WriteLine("Waiting for connection...");
               server.WaitForConnection();
               Console.WriteLine("Connected.");
               var br = new BinaryReader(server);
               var bw = new BinaryWriter(server);
               string UN = username2.Text;
               string PW = password2.Text;
               string EM = email.Text;
               string FD = folderdir.Text;
               string[] send = new string[5];
               send[0]="register";
               send[1]=UN;
               send[2]=PW;
               send[3]=EM;
               send[4]=FD;
               for(int i=0; i<send.Length;i++)

                try
                {

                     var str = new string(send[i].ToArray());  // Just for fun

                    var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array
                    bw.Write((uint)buf.Length);                // Write string length
                    bw.Write(buf);                              // Write string
                    Console.WriteLine("Wrote: \"{0}\"", str);
                }
                catch (EndOfStreamException)
                {
                    Console.WriteLine("Client disconnected.");
                    server.Close();
                    server.Dispose();   // When client disconnects
                }

                     var len2 = (int)br.ReadUInt32();            // Read string length
                     var str2 = new string(br.ReadChars(len2));    // Read string
                     MessageBox.Show(str2);
        }
开发者ID:jonathanharmatz,项目名称:Project,代码行数:41,代码来源:Form2.cs

示例14: ServerThread

    private static void ServerThread(object data)
    {
        NamedPipeServerStream pipeServer =
            new NamedPipeServerStream("testpipe", PipeDirection.InOut, numThreads);

        int threadId = Thread.CurrentThread.ManagedThreadId;

        // Wait for a client to connect
        pipeServer.WaitForConnection();

        Console.WriteLine("Client connected on thread[{0}].", threadId);
        //try
        //{
        //    // Read the request from the client. Once the client has
        //    // written to the pipe its security token will be available.

        //    StreamString ss = new StreamString(pipeServer);

        //    // Verify our identity to the connected client using a
        //    // string that the client anticipates.

        //    ss.WriteString("I am the one true server!");
        //    string filename = ss.ReadString();

        //    // Read in the contents of the file while impersonating the client.
        //    ReadFileToStream fileReader = new ReadFileToStream(ss, filename);

        //    // Display the name of the user we are impersonating.
        //    Console.WriteLine("Reading file: {0} on thread[{1}] as user: {2}.",
        //        filename, threadId, pipeServer.GetImpersonationUserName());
        //    pipeServer.RunAsClient(fileReader.Start);
        //}
        //// Catch the IOException that is raised if the pipe is broken
        //// or disconnected.
        //catch (IOException e)
        //{
        //    Console.WriteLine("ERROR: {0}", e.Message);
        //}
        pipeServer.Close();
    }
开发者ID:ma581,项目名称:TestingPipes,代码行数:40,代码来源:PipeServer.cs

示例15: Main

        static void Main(string[] args)
        {
            while (true)
            {
                //Create pipe instance
                NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("mojotestpipe", PipeDirection.InOut, 4);
                Console.WriteLine(String.Format("[DOTNET] {0} NamedPipeServerStream thread created.", DateTime.Now.ToString("T")));

                //wait for connection
                Console.WriteLine(String.Format("[DOTNET] {0} Wait for a client to connect...", DateTime.Now.ToString("T")));
                pipeServer.WaitForConnection();

                Console.WriteLine(String.Format("[DOTNET] {0} Client connected.", DateTime.Now.ToString("T")));
                try
                {
                    // Stream for the request.
                    StreamReader sr = new StreamReader(pipeServer);
                    // Stream for the response.
                    StreamWriter sw = new StreamWriter(pipeServer);
                    sw.AutoFlush = true;

                    // Read request from the stream.
                    string echo = sr.ReadLine();

                    Console.WriteLine(String.Format("[DOTNET] {0} Request message: {1}", DateTime.Now.ToString("T"), echo));

                    // Write response to the stream.
                    sw.WriteLine("[ECHO]: " + echo);

                    pipeServer.Disconnect();
                }
                catch (IOException e)
                {
                    Console.WriteLine(String.Format("[DOTNET] {0} Error: {1}", DateTime.Now.ToString("T"), e.Message));
                }
                pipeServer.Close();
            }
        }
开发者ID:jagdishRangaswamy,项目名称:cloudera-connector,代码行数:39,代码来源:Program.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。