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


C# NamedPipeServerStream.BeginWaitForConnection方法代码示例

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


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

示例1: PipeServerAsyncEnumerator

		private static IEnumerator<Int32> PipeServerAsyncEnumerator(AsyncEnumerator ae) {
			// Each server object performs asynchronous operation on this pipe
			using (var pipe = new NamedPipeServerStream(
				"Echo", PipeDirection.InOut, -1, PipeTransmissionMode.Message,
				PipeOptions.Asynchronous | PipeOptions.WriteThrough)) {
				// Asynchronously accept a client connection
				pipe.BeginWaitForConnection(ae.End(), null);
				yield return 1;

				// A client connected, let's accept another client
				var aeNewClient = new AsyncEnumerator();
				aeNewClient.BeginExecute(PipeServerAsyncEnumerator(aeNewClient),
					aeNewClient.EndExecute);

				// Accept the client connection
				pipe.EndWaitForConnection(ae.DequeueAsyncResult());

				// Asynchronously read a request from the client
				Byte[] data = new Byte[1000];
				pipe.BeginRead(data, 0, data.Length, ae.End(), null);
				yield return 1;

				// The client sent us a request, process it
				Int32 bytesRead = pipe.EndRead(ae.DequeueAsyncResult());

				// Just change to upper case
				data = Encoding.UTF8.GetBytes(
					Encoding.UTF8.GetString(data, 0, bytesRead).ToUpper().ToCharArray());

				// Asynchronously send the response back to the client
				pipe.BeginWrite(data, 0, data.Length, ae.End(), null);
				yield return 1;

				// The response was sent to the client, close our side of the connection
				pipe.EndWrite(ae.DequeueAsyncResult());
			} // Close happens in a finally block now!
		}
开发者ID:Helen1987,项目名称:edu,代码行数:37,代码来源:PipeServerLib.cs

示例2: WaitForConnectionCallBack

        private void WaitForConnectionCallBack(IAsyncResult iar)
        {
            try
            {
                // Get the pipe
                NamedPipeServerStream pipeServer = (NamedPipeServerStream) iar.AsyncState;
                // End waiting for the connection
                pipeServer.EndWaitForConnection(iar);

                StreamReader sr = new StreamReader(pipeServer);
                StreamWriter sw = new StreamWriter(pipeServer);


                var response = ProccesQueries(sr.ReadLine());
                sw.WriteLine(response);
                sw.Flush();
                pipeServer.WaitForPipeDrain();

                // Kill original sever and create new wait server
                pipeServer.Disconnect();
                pipeServer.Close();
                pipeServer = null;
                pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte,
                                                       PipeOptions.Asynchronous);

                // Recursively wait for the connection again and again....
                pipeServer.BeginWaitForConnection(WaitForConnectionCallBack, pipeServer);
            }
            catch (Exception e)
            {
                Log.Debug("Pipe server error", e);
            }
        }
开发者ID:kwagalajosam,项目名称:digiCamControl,代码行数:33,代码来源:PipeServerT.cs

示例3: PipeServer

 public PipeServer()
 {
     PipeName = string.Format("exTibiaS{0}", GameClient.Process.Id);
     Pipe = new NamedPipeServerStream(PipeName, PipeDirection.InOut, -1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
     OnReceive += new PipeListener(PipeServer_OnReceive);
     Pipe.BeginWaitForConnection(new AsyncCallback(BeginWaitForConnection), null);
 }
开发者ID:PimentelM,项目名称:extibiabot,代码行数:7,代码来源:PipeServer.cs

示例4: Start

        // Method ====================================================================================
        public void Start(string name)
        {
            pipeName = name;

            isExitThread = false;
            Thread thread = new Thread(() =>
            {
                while (true) {
                    if (isExitThread == true) {
                        isExitThread = false;
                        break;
                    }

                    try {
                        // xp 无法使用pipe,所以加点延迟预防一下...
                        Thread.Sleep(500);
                        NamedPipeServerStream pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, -1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
                        pipeServer.BeginWaitForConnection(ReadCallback, pipeServer);
                    } catch (Exception ex) {
                        Logger.WriteException(ex);
                    }
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }
开发者ID:yiend,项目名称:mnncs,代码行数:28,代码来源:PipeServer.cs

示例5: Pipe

 /// <summary>
 ///  Creates a Pipe to interact with an injected DLL or another program.
 /// </summary>
 public Pipe(Client client, string name)
 {
     this.client = client;
     this.name = name;
     pipe = new NamedPipeServerStream(name, PipeDirection.InOut, -1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
     pipe.BeginWaitForConnection(new AsyncCallback(BeginWaitForConnection), null);
 }
开发者ID:Xileck,项目名称:tibiaapi,代码行数:10,代码来源:Pipe.cs

示例6: WaitForConnectionCallBack

        private void WaitForConnectionCallBack(IAsyncResult iar)
        {
            try
            {
                // Get the pipe
                NamedPipeServerStream pipeServer = (NamedPipeServerStream)iar.AsyncState;
                // End waiting for the connection
                pipeServer.EndWaitForConnection(iar);
                byte[] buffer = new byte[10000];
                // Read the incoming message
                pipeServer.Read(buffer, 0, 10000);
                // Convert byte buffer to string
                string stringData = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                Debug.WriteLine(stringData + Environment.NewLine);
                // Pass message back to calling form
                PipeMessage.Invoke(stringData);

                // Kill original sever and create new wait server
                pipeServer.Close();
                pipeServer = null;
                pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                // Recursively wait for the connection again and again....
                pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);
            }
            catch
            {
                return;
            }
        }
开发者ID:tbalci,项目名称:EFPT,代码行数:30,代码来源:PipeServer.cs

示例7: NewAccept

        static void NewAccept()
        {
            var stream = new NamedPipeServerStream("Dwarrowdelf.Pipe", PipeDirection.InOut, 4, PipeTransmissionMode.Byte,
                PipeOptions.Asynchronous);

            stream.BeginWaitForConnection(AcceptCallback, stream);
        }
开发者ID:tomba,项目名称:dwarrowdelf,代码行数:7,代码来源:PipeConnectionListener.cs

示例8: CreatePipeListener

 private static void CreatePipeListener()
 {
     var pipe = new NamedPipeServerStream("XBEE SAMPLE", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
     //var security = pipe.GetAccessControl();
     //security.AddAccessRule(new PipeAccessRule("rob-pc\\rob", PipeAccessRights.FullControl, AccessControlType.Allow));
     //pipe.SetAccessControl(security);
     pipe.BeginWaitForConnection(Pipe_Connected, pipe);
 }
开发者ID:rtennys,项目名称:XBee,代码行数:8,代码来源:Program.cs

示例9: Pipe

 /// <summary>
 /// Initializes a new instance of the <see cref="Pipe"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="name">The name.</param>
 public Pipe(ConnectionProvider connection, string name)
 {
     Connection = connection;
     Name = name;
     Buffer = new byte[1024];
     pipe = new NamedPipeServerStream(name, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
     pipe.BeginWaitForConnection(new AsyncCallback(BeginWaitForConnection), null);
 }
开发者ID:alexisjojo,项目名称:ktibiax,代码行数:13,代码来源:Pipe.cs

示例10: StartInteropServer

 private void StartInteropServer()
 {
     if (pipeServer != null)
     {
         pipeServer.Close();
         pipeServer = null;
     }
     pipeServer = new NamedPipeServerStream("SpeditNamedPipeServer", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
     pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnection_MessageIn), null);
 }
开发者ID:not1ce111,项目名称:Spedit,代码行数:10,代码来源:PipeInteropServer.cs

示例11: Start

        public void Start(string pipeName)
        {
            _pipeName = pipeName;

            var security = new PipeSecurity();
            var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            security.AddAccessRule(new PipeAccessRule(sid, PipeAccessRights.FullControl, AccessControlType.Allow));
            _pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 254,
                PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 4096, 4096, security);
            _pipeServer.BeginWaitForConnection(WaitForConnectionCallBack, _pipeServer);
            _logger.Info("Opened named pipe '{0}'", _pipeName);
            _closed = false;
        }
开发者ID:SpoinkyNL,项目名称:Artemis,代码行数:13,代码来源:PipeServer.cs

示例12: NamedPipe

        public NamedPipe(string name, string server, IEnumerable<string[]> dataValueArrays)
        {
            _dataValueArrays = dataValueArrays;

              Name = name;
              Server = server;
              Stream = new NamedPipeServerStream(name, PipeDirection.Out, 2, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

              if (Log.IsDebugEnabled)
              {
            Log.DebugFormat("Listening on named pipe {0}", Path);
              }

              Stream.BeginWaitForConnection(OnConnection, this);
        }
开发者ID:GrimaceOfDespair,项目名称:BulkInsert,代码行数:15,代码来源:NamedPipe.cs

示例13: ServerLoop

 private void ServerLoop()
 {
     while (_stopRequired)
     {
         _allDone.Reset();
         var pipeStream = new NamedPipeServerStream(PipeName, PipeDirection.InOut, -1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);                
         pipeStream.BeginWaitForConnection(asyncResult =>
                                               {                                                          
                                                   pipeStream.EndWaitForConnection(asyncResult);
                                                   _allDone.Set();
                                                   var thread = new Thread(ProcessClientThread);
                                                   thread.Start(pipeStream);
                                               }, null);
         _allDone.WaitOne();
     }
 }
开发者ID:webbers,项目名称:dongle.net,代码行数:16,代码来源:PipeServer.cs

示例14: Listen

        /// <summary>
        /// Start the listening process
        /// </summary>
        /// <param name="source">Name of pipe to be listend to</param>
        public void Listen(string source)
        {

            try
            {
                _pipeName = source;
                var pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
                //old school style - may want to go async/await in future
                pipeServer.BeginWaitForConnection(new AsyncCallback(ConnectionCallback), pipeServer);

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
开发者ID:cefoot,项目名称:KAIT,代码行数:20,代码来源:DemographcisNamedPipeService.cs

示例15: PipeServer

 public PipeServer(string serverName)
 {
     try
     {
         ServerName = serverName;
         _pipe = new NamedPipeServerStream(ServerName, PipeDirection.In, 5, PipeTransmissionMode.Byte,
                                           PipeOptions.Asynchronous);
         _pipe.BeginWaitForConnection(ConnectionHandler, _pipe);
         IsOk = true;
     }
     catch (Exception e)
     {
         IsOk = false;
         Issue = e;
     }
 }
开发者ID:jardrake03,项目名称:incert,代码行数:16,代码来源:NamedPipeServer.cs


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