本文整理汇总了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!
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
}
示例7: NewAccept
static void NewAccept()
{
var stream = new NamedPipeServerStream("Dwarrowdelf.Pipe", PipeDirection.InOut, 4, PipeTransmissionMode.Byte,
PipeOptions.Asynchronous);
stream.BeginWaitForConnection(AcceptCallback, stream);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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;
}
}