Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can write a multi threaded pipe server by repeatedly creating a NamedPipeServerStream and waiting for one connection, then spawning a thread for that instance of NamedPipeServerStream. </p> <p>You can only have 254 concurrent clients though according to the .NET MSDN documentation linked below. For Win32 APIs though you can pass a special value to get unlimited based on system resources. It seems the MSDN documentation is wrong as noted below. </p> <p>The below code is not tested so please do not simply copy and paste for production use without testing:</p> <pre><code> public class PipeServer { bool running; Thread runningThread; EventWaitHandle terminateHandle = new EventWaitHandle(false, EventResetMode.AutoReset); public string PipeName { get; set; } void ServerLoop() { while (running) { ProcessNextClient(); } terminateHandle.Set(); } public void Run() { running = true; runningThread = new Thread(ServerLoop); runningThread.Start(); } public void Stop() { running = false; terminateHandle.WaitOne(); } public virtual string ProcessRequest(string message) { return ""; } public void ProcessClientThread(object o) { NamedPipeServerStream pipeStream = (NamedPipeServerStream)o; //TODO FOR YOU: Write code for handling pipe client here pipeStream.Close(); pipeStream.Dispose(); } public void ProcessNextClient() { try { NamedPipeServerStream pipeStream = new NamedPipeServerStream(PipeName, PipeDirection.InOut, 254); pipeStream.WaitForConnection(); //Spawn a new thread for each request and continue waiting Thread t = new Thread(ProcessClientThread); t.Start(pipeStream); } catch (Exception e) {//If there are no more avail connections (254 is in use already) then just keep looping until one is avail } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload