Giter VIP home page Giter VIP logo

named-pipes's Introduction

Named-Pipes

Inter-process communication library using named pipes.

Full details can be found here: http://www.codeproject.com/Articles/864679/Creating-a-Server-Using-Named-Pipes

In this repository I show how I created a server and client implementation using named pipes in C# .Net 4. I used NamedPipeServerStream and NamedPipeClientStream, but soon realized that the name "server" was confusing. NamedPipeServerStream could only handle one client at a time (see Named Pipe Instances topic in MSDN), but I needed a server that could handle multiple clients requests. I could not find any online example suitable to my needs, therefore, I created my own implementation of a server using NamedPipeServerStream and NamedPipeClientStream.

Introduction to the code PipeServer is in charge of creating and holding the named pipe streams, which are opened for each client. InternalPipeServer is a wrapper for NamedPipeServerStream. PipeClient is a wrapper for NamedPipeClientStream.

Main flows:

  1. PipeServer is created and started 1.1. A new pipe name is generated. 1.2. A new instance of InternalPipeServer is created and begins waiting for client connections.
  2. PipeClient is created and started 2.1. A connection is made with InternalPipeServer. 2.2. InternalPipeServer fires an event to let PipeServer know a connection was made. 2.2.1. PipeServer fires its own event, to let the world know that a client has connected. It then creates a new instance of InternalPipeServer and starts it so that it will begin waiting for new connections, while the first instance communicates with the first client. 2.3. InternalPipeServer begins an asynchronous read operation which completes when a client has sent a message, has been disconnected or when the pipe has been closed.
  3. PipeClient sends a message 3.1 InternalPipeServer receives part of the message since the message is longer than its buffer size, and initiates a new asynchronous read operation. 3.2 InternalPipeServer receives the rest of the message, appends it to the first parts, fires an event to let PipeServer know a new message has arrived, and initiates a new asynchronous read operation to wait for new messages. 3.2.1 PipeServer fires its own event to let the world know a new message has arrived from one of the clients.
  4. PipeClient disconnects 4.1 InternalPipeServer's read operation ends with no bytes read, so InternalPipeServer assumes the client has disconnected. It fires an event to let PipeServer know about it. 4.2 PipeServer fires its own event to let the world know a client has been disconnected.
  5. PipeServer is stopped 5.1 PipeServer stops all its InternalPipeServer instances

Using the code If you need to communicate with another process, use this code. Create a PipeServer in one process and a PipeClient in another. Then use PipeClient in order to send messages to the server.

named-pipes's People

Contributors

ifatchitin avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.