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


C# NamedPipeClientStream.Write方法代码示例

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


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

示例1: Main

		static void Main()
		{
			ClearModifierKeys();

			var args = Environment.GetCommandLineArgs();
			var multi = args.Any(arg => arg == "-multi");

			if ((multi) || (mutex.WaitOne(TimeSpan.Zero, true)))
			{
				var app = new App();
				if (!multi)
					SetupPipeWait(app);
				app.Run();
				if (!multi)
					mutex.ReleaseMutex();
				return;
			}

			// Server already exists; connect and send command line
			var pipeClient = new NamedPipeClientStream(".", IPCName, PipeDirection.InOut);
			pipeClient.Connect();
			var buf = Coder.StringToBytes(string.Join(" ", args.Skip(1).Select(arg => $"\"{arg.Replace(@"""", @"""""")}\"")), Coder.CodePage.UTF8);
			var size = BitConverter.GetBytes(buf.Length);
			pipeClient.Write(size, 0, size.Length);
			pipeClient.Write(buf, 0, buf.Length);
		}
开发者ID:xyandro,项目名称:NeoEdit,代码行数:26,代码来源:InstanceManager.cs

示例2: SendMessage

        /// <summary>
        /// Sends message to all remote listeners
        /// </summary>
        /// <param name="data">Message data</param>
        protected override void SendMessage(byte[] data)
        {
            foreach (var pipeConfiguration in _clientPipesConfiguration)
            {
                using (var namedPipeClient = new NamedPipeClientStream(
                    pipeConfiguration.ServerName, pipeConfiguration.Name))
                {
                    try
                    {
                        _log.DebugFormat("Send message to {0}\\{1}",
                            pipeConfiguration.ServerName, pipeConfiguration.Name);

                        if (!ConnectToPipe(namedPipeClient))
                        {
                            _log.WarnFormat("Couldn't connect to pipe {0}\\{1}",
                                pipeConfiguration.ServerName, pipeConfiguration.Name);
                            continue;
                        }

                        namedPipeClient.Write(data, 0, data.Length);
                    }
                    catch (IOException ex)
                    {
                        _log.Warn("Exception while sending a message", ex);
                    }
                }
            }
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:32,代码来源:NamedPipeMessageBus.cs

示例3: ClientSendsByteServerReceives

    public static void ClientSendsByteServerReceives()
    {
        using (NamedPipeServerStream server = new NamedPipeServerStream("foo", PipeDirection.In))
        {
            byte[] sent = new byte[] { 123 };
            byte[] received = new byte[] { 0 };
            Task t = Task.Run(() =>
                {
                    using (NamedPipeClientStream client = new NamedPipeClientStream(".", "foo", PipeDirection.Out))
                    {
                        client.Connect();
                        Assert.True(client.IsConnected);

                        client.Write(sent, 0, 1);
                    }
                });
            server.WaitForConnection();
            Assert.True(server.IsConnected);

            int bytesReceived = server.Read(received, 0, 1);
            Assert.Equal(1, bytesReceived);

            t.Wait();
            Assert.Equal(sent[0], received[0]);
        }
    }
开发者ID:gitter-badger,项目名称:corefx,代码行数:26,代码来源:NamedPipesSimpleTest.cs

示例4: SendBreakRequest

 public static void SendBreakRequest()
 {
     using (NamedPipeClientStream client = new NamedPipeClientStream(PIPENAME)) {
         client.Connect();
         client.Write(BREAK, 0, BREAK.Length);
     }
 }
开发者ID:pcluddite,项目名称:WinMonkey,代码行数:7,代码来源:PipeWatcher.cs

示例5: PipesWriter

        private static void PipesWriter(string pipeName)
        {
            try
            {
                using (var pipeWriter = new NamedPipeClientStream("TheRocks", pipeName, PipeDirection.Out))
                {
                    pipeWriter.Connect();
                    WriteLine("writer connected");

                    bool completed = false;
                    while (!completed)
                    {
                        string input = ReadLine();
                        if (input == "bye") completed = true;

                        byte[] buffer = Encoding.UTF8.GetBytes(input);
                        pipeWriter.Write(buffer, 0, buffer.Length);
                    }
                }
                WriteLine("completed writing");
            }
            catch (Exception ex)
            {
                WriteLine(ex.Message);
            }
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:26,代码来源:Program.cs

示例6: CheckUnenrolledHostShouldRemoved

        public void CheckUnenrolledHostShouldRemoved()
        {
            CredentialReceiver.instance.Init();
            ServerListHelper.instance.Init();
            DatabaseManager.CreateNewConnection(dbName);
            IXenConnection connection = DatabaseManager.ConnectionFor(dbName);
            Session _session = DatabaseManager.ConnectionFor(dbName).Session;
            DatabaseManager.ConnectionFor(dbName).LoadCache(_session);
            Dictionary<string, string> config = cleanStack();
            connection.LoadCache(_session);

            int conSize = ServerListHelper.instance.GetServerList().Count;

            NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
            pipeClient.Connect();
            string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { connection.Hostname, connection.Username, connection.Password }));
            pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length);
            pipeClient.Close();
            System.Threading.Thread.Sleep(1000);
            List<ServerInfo> con = ServerListHelper.instance.GetServerList();
            Assert.IsTrue(con.Count == conSize + 1);


            //1. If XenServer has not enroll, lock will not been set.
            config = cleanStack();
            config[HealthCheckSettings.STATUS] = "false";
            Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
            Assert.IsFalse(RequestUploadTask.Request(connection, _session));
            con = ServerListHelper.instance.GetServerList();
            Assert.IsTrue(con.Count == conSize);
            CredentialReceiver.instance.UnInit();
        }
开发者ID:robhoes,项目名称:xenadmin,代码行数:32,代码来源:RequestUploadTaskTests.cs

示例7: Main

        static void Main()
        {
            try
            {
                using (var pipe = new NamedPipeClientStream(".", "sharp-express", PipeDirection.InOut))
                {
                    pipe.Connect();

                    var encoding = Encoding.UTF8;
                    var sb = new StringBuilder();
                    sb.Append("GET / HTTP/1.1\r\n");
                    sb.Append("Header1: Hi!\r\n");
                    sb.Append("\r\n");

                    var bytes = encoding.GetBytes(sb.ToString());
                    pipe.Write(bytes, 0, bytes.Length);
                    pipe.Flush();

                    var buf = new byte[64 * 1024];
                    var size = pipe.Read(buf, 0, buf.Length);
                    var message = encoding.GetString(buf, 0, size);
                    Console.WriteLine(message);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.ReadLine();
        }
开发者ID:lstefano71,项目名称:SharpExpress,代码行数:31,代码来源:Program.cs

示例8: Main

        static void Main()
        {
            try {
                using (var npcs = new NamedPipeClientStream("Stream Mosaic")) {
                    try {
                        npcs.Connect(500);

                        var url = Environment.CommandLine.Substring(Environment.CommandLine.IndexOf(' ')).Trim();

                        var textBytes = Encoding.UTF8.GetBytes(url);
                        npcs.Write(textBytes, 0, textBytes.Length);
                        npcs.Flush();

                        var responseBytes = new byte[1];
                        npcs.Read(responseBytes, 0, 1);
                    } catch (TimeoutException) {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new MainWindow());
                    }
                }
            } catch (Exception exc) {
                MessageBox.Show(exc.ToString());
            }
        }
开发者ID:kg,项目名称:StreamMosaic,代码行数:25,代码来源:Program.cs

示例9: WriteMessage

 protected override void WriteMessage(Byte[] message)
 {
     message = message ?? Empty;
     using (var pipeStream = new NamedPipeClientStream(serverName, pipeName, PipeDirection.InOut, PipeOptions.None))
     {
         pipeStream.Connect(timeout);
         pipeStream.Write(message, 0, message.Length);
     }
 }
开发者ID:khalidabuhakmeh,项目名称:Harvester,代码行数:9,代码来源:NamedPipeClientBuffer.cs

示例10: Main

        static void Main(string[] args)
        {
            string[] simpleNames = { "Yukari", "Maki", "Zunko", "Akane", "Aoi", "Koh" };
            string[] simpleNamesA = { "yukari", "maki", "zunko", "akane", "aoi", "koh" };

            //引数のチェック
            if (args.Length < 2) {
                string mergeName = "";
                for (int i = 0; i < simpleNames.Length; i++)
                {
                    mergeName = mergeName + simpleNames[i];
                    //ワード間に", "をつける
                    if (i < simpleNames.Length - 1)
                        mergeName = mergeName + ", ";
                }
                Console.WriteLine("引数を指定してください: VoiceroidTClient"+ mergeName +" [会話内容];[音量0.0-2.0];[話速0.5-4.0];[高さ0.5-2.0];[抑揚0.0-2.0]");
                return;
            }
            //引数に設定されたボイスロイドの名前をチェック
            string selectedSimple = null;
            for (int i = 0; i < simpleNames.Length; i++) {
                if (args[0].CompareTo(simpleNames[i]) == 0 || args[0].CompareTo(simpleNamesA[i]) == 0) {
                    selectedSimple = simpleNames[i];
                }
            }
            if (selectedSimple == null) {
                string mergeName = "";
                for (int i = 0; i < simpleNames.Length; i++)
                {
                    mergeName = mergeName + simpleNames[i];
                    //ワード間に", "をつける
                    if (i < simpleNames.Length - 1)
                        mergeName = mergeName + ", ";
                }
                Console.WriteLine("第一引数に指定されたVOICEROIDの名前が正しくありません. 使用できる名前は次のとおりです: "+ mergeName);
                return;
            }
            //サーバーとの通信処理を開始
            string message = args[1];
            try {
                //サーバーのセッションを取得する
                using (NamedPipeClientStream client = new NamedPipeClientStream("voiceroid_talker" + selectedSimple)) {
                        client.Connect(1000);
                    //サーバにーメッセージを送信する
                    byte[] buffer = UnicodeEncoding.Unicode.GetBytes(message);
                    client.Write(buffer, 0, buffer.Length);
                    byte[] response = new byte[4];
                    client.Read(response, 0, response.Length);
                    client.Close();
                }
            } catch (Exception e) {
                //サーバーに接続できない時、通信エラーが発生した場合
                Console.WriteLine("VoiceroidTServerによるサーバー, [voiceroid_talker" + selectedSimple + "]が見つかりません.");
            }
        }
开发者ID:blkcatman,项目名称:VoiceroidTalker,代码行数:55,代码来源:Program.cs

示例11: SendPipeMessgae

 public static void SendPipeMessgae(String mes)
 {
     using (NamedPipeClientStream clientStream = new NamedPipeClientStream("zjlrcpipe"))
     {
         // connect to the pipe sever
         clientStream.Connect();
         UTF8Encoding encoding = new UTF8Encoding();
         Byte[] bytes = encoding.GetBytes(mes);
         clientStream.Write(bytes, 0, bytes.Length);
     }
 }
开发者ID:zhaojunlucky,项目名称:Audio,代码行数:11,代码来源:PipeServer.cs

示例12: Start

 // Use this for initialization
 void Start()
 {
     System.IO.Pipes.NamedPipeClientStream clientStream = new System.IO.Pipes.NamedPipeClientStream ("mypipe");
     clientStream.Connect (60);
     byte[] buffer = ASCIIEncoding.ASCII.GetBytes ("Connected/n");
     Debug.Log ("connected");
     clientStream.Write (buffer, 0, buffer.Length);
     clientStream.Flush ();
     clientStream.Dispose ();
     clientStream.Close ();
 }
开发者ID:Lucasvo1,项目名称:FHVGame,代码行数:12,代码来源:PipeClient.cs

示例13: Main

        static void Main(string[] args)
        {
            string pipeString = "Hello hello hello!";
            byte[] pipeBuffer = new byte[pipeString.Length * sizeof(char)];
            System.Buffer.BlockCopy(pipeString.ToCharArray(), 0, pipeBuffer, 0, pipeString.Length);

            NamedPipeClientStream pipe = new NamedPipeClientStream(".", "MyServicePipe", PipeDirection.Out, PipeOptions.WriteThrough, System.Security.Principal.TokenImpersonationLevel.Impersonation);
            pipe.Connect();
            pipe.Write(pipeBuffer, 0, pipeBuffer.Length);
            Thread.Sleep(10000);
            pipe.Close();
        }
开发者ID:jmguill,项目名称:my-service,代码行数:12,代码来源:Program.cs

示例14: SendToPipe

    void SendToPipe()
    {
        byte[] buffer = ASCIIEncoding.ASCII.GetBytes ("done");
        System.IO.Pipes.NamedPipeClientStream clientStream = new System.IO.Pipes.NamedPipeClientStream ("mypipe");
        clientStream.Connect (System.TimeSpan.MaxValue.Seconds);
        clientStream.WaitForPipeDrain();
        clientStream.Write (buffer, 0, buffer.Length);

        clientStream.Flush ();
        clientStream.Dispose();
        clientStream.Close();
    }
开发者ID:Lucasvo1,项目名称:FHVGame,代码行数:12,代码来源:PipeClient.cs

示例15: Run

        protected override void Run()
        {
            NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", CallHomeSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
            int retryCount = 120;
            do
            {
                try
                {
                    pipeClient.Connect(0);
                }
                catch (System.TimeoutException exp)
                {
                    throw exp;
                }
                catch
                {
                    System.Threading.Thread.Sleep(1000);
                    pipeClient = null;
                    pipeClient = new NamedPipeClientStream(".", CallHomeSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
                }
            } while (!pipeClient.IsConnected && retryCount-- != 0);

            foreach (Host host in pool.Connection.Cache.Hosts)
            {
                if (host.IsMaster())
                {
                    string credential;
                    if (callHomeSettings.Status == CallHomeStatus.Enabled)
                        credential = ProtectCredential(host.address, username, password);
                    else
                        credential = ProtectCredential(host.address, string.Empty, string.Empty);
                    pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length);
                    break;
                }
            }

            pipeClient.Write(Encoding.UTF8.GetBytes(CallHomeSettings.HEALTH_CHECK_PIPE_END_MESSAGE), 0, CallHomeSettings.HEALTH_CHECK_PIPE_END_MESSAGE.Length);
            pipeClient.Close();
        }
开发者ID:0dr4c1R,项目名称:xenadmin,代码行数:39,代码来源:TransferCallHomeSettingAction.cs


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