Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multiple pipes

Multiple pipes

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmin
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A T I F
    wrote on last edited by
    #1

    A named pipe is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and handles, and provides a separate conduit for client-server communication. The use of instances enables multiple pipe clients to use the same named pipe simultaneously. Can anyone point me in the right direction for creating multiple named pipe of the same name and using multiple clients over it. i.e how do a client distinguish which pipe to connect if we have two pipes created in two process with the same name.

    V A 2 Replies Last reply
    0
    • A A T I F

      A named pipe is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and handles, and provides a separate conduit for client-server communication. The use of instances enables multiple pipe clients to use the same named pipe simultaneously. Can anyone point me in the right direction for creating multiple named pipe of the same name and using multiple clients over it. i.e how do a client distinguish which pipe to connect if we have two pipes created in two process with the same name.

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      One the Win32 platform, in theory instanses of the named pipe could be distinguished via handles. One the UNIX platform, consider, for example, a file descriptor. Kuphryn

      A 1 Reply Last reply
      0
      • V valikac

        One the Win32 platform, in theory instanses of the named pipe could be distinguished via handles. One the UNIX platform, consider, for example, a file descriptor. Kuphryn

        A Offline
        A Offline
        A T I F
        wrote on last edited by
        #3

        I am sorry but if two different processes create a named pipe with the same name how can the client differ in the two? A client would not have handles to any.

        V 1 Reply Last reply
        0
        • A A T I F

          I am sorry but if two different processes create a named pipe with the same name how can the client differ in the two? A client would not have handles to any.

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          One possible solution is via process ID or the name of the window? Kuphryn

          1 Reply Last reply
          0
          • A A T I F

            A named pipe is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and handles, and provides a separate conduit for client-server communication. The use of instances enables multiple pipe clients to use the same named pipe simultaneously. Can anyone point me in the right direction for creating multiple named pipe of the same name and using multiple clients over it. i.e how do a client distinguish which pipe to connect if we have two pipes created in two process with the same name.

            A Offline
            A Offline
            Antti Keskinen
            wrote on last edited by
            #5

            What you're planning is not possible. Two different pipe server processes can not create a named pipe with the same name. From MSDN: Each named pipe has a unique name that distinguishes it from other named pipes in the system's list of named objects. The way named pipes work is pretty straight-forward. Firstly, you have a pipe server process that is responsible for creating pipe instances. The function CreateNamedPipe creates either the first instance of a named pipe, or a new instances of an existing pipe. Like MSDN states, each of these instances have their own buffers and handles. When the first instance of the pipe is created, this pipe-name becomes unique to this process. No other pipe server process can create a named pipe with the same name. Attempting such would result in an error code (ERROR_BAD_PIPE or ERROR_INVALID_HANDLE). After the pipe instance is created, ConnectNamedPipe prepares this created pipe instance for client connections. Each instance of a named pipe MUST be prepared by the server before a connection from a client is possible. This server process can then, as it sees fit, create and prepare more instances of the same pipe or instances of differently-named pipes. Clients can then use CallNamedPipe to connect, transact and disconnect from an (undetermined) instance of the named pipe. If the server has run out of free pipe instances, an error value is returned (ERROR_PIPE_BUSY), or optionally, the function can wait until a pipe instance becomes available. The clients can not distinguish which pipe instance they are connecting to. All instances of a named pipe are similar by outside aspects, i.e. they provide precisely the similar type of services. If you need a type A pipe for one client and type B pipe for another client, you must create two named pipes, which both have a seperate unique name. See the idea ? Server creates and initializes named pipe instances (one or more instances of the same named pipe, and/or one or more instances of several named pipes), and clients request an access to these instances for data transfer, identifying the requested named pipe by it's name. But the clients can not determine the specific instance of the pipe they wish to connect to. This is determined by the server. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

            A 1 Reply Last reply
            0
            • A Antti Keskinen

              What you're planning is not possible. Two different pipe server processes can not create a named pipe with the same name. From MSDN: Each named pipe has a unique name that distinguishes it from other named pipes in the system's list of named objects. The way named pipes work is pretty straight-forward. Firstly, you have a pipe server process that is responsible for creating pipe instances. The function CreateNamedPipe creates either the first instance of a named pipe, or a new instances of an existing pipe. Like MSDN states, each of these instances have their own buffers and handles. When the first instance of the pipe is created, this pipe-name becomes unique to this process. No other pipe server process can create a named pipe with the same name. Attempting such would result in an error code (ERROR_BAD_PIPE or ERROR_INVALID_HANDLE). After the pipe instance is created, ConnectNamedPipe prepares this created pipe instance for client connections. Each instance of a named pipe MUST be prepared by the server before a connection from a client is possible. This server process can then, as it sees fit, create and prepare more instances of the same pipe or instances of differently-named pipes. Clients can then use CallNamedPipe to connect, transact and disconnect from an (undetermined) instance of the named pipe. If the server has run out of free pipe instances, an error value is returned (ERROR_PIPE_BUSY), or optionally, the function can wait until a pipe instance becomes available. The clients can not distinguish which pipe instance they are connecting to. All instances of a named pipe are similar by outside aspects, i.e. they provide precisely the similar type of services. If you need a type A pipe for one client and type B pipe for another client, you must create two named pipes, which both have a seperate unique name. See the idea ? Server creates and initializes named pipe instances (one or more instances of the same named pipe, and/or one or more instances of several named pipes), and clients request an access to these instances for data transfer, identifying the requested named pipe by it's name. But the clients can not determine the specific instance of the pipe they wish to connect to. This is determined by the server. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

              A Offline
              A Offline
              A T I F
              wrote on last edited by
              #6

              Thanks for the response. I will see how I can work this out...... Can you please clarify what nDefaultTimeOut parameter stands for in CreateNamedPipe call and what is its connection to WaitNamedPipe etc call(s) if any.

              A 1 Reply Last reply
              0
              • A A T I F

                Thanks for the response. I will see how I can work this out...... Can you please clarify what nDefaultTimeOut parameter stands for in CreateNamedPipe call and what is its connection to WaitNamedPipe etc call(s) if any.

                A Offline
                A Offline
                Antti Keskinen
                wrote on last edited by
                #7

                This parameter of the call specifies the time, in milliseconds, that a client connecting to the pipe will wait for when no free pipe instances are available. You can determine how long the client side function will wait before issuing a time-out. It can be a certain time in milliseconds, the default wait time specified by the server, or it can wait forever. Here, the default wait time specified by the server is the key phrase. This time period is determined by the nDefaultTimeOut parameter. Each pipe instance created by CreateNamedPipe must specify the same time-out value. This value is supplied only so that clients, which use WaitNamedPipe or CallNamedPipe functions to connect to the named pipe, know how long they should wait, by default, before issuing a time-out error. If, during this time period, a pipe instance becomes available (the server creates a new instance or some other client disconnects from one pipe instance), then the client-side pipe function will connect to this available pipe. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

                A 1 Reply Last reply
                0
                • A Antti Keskinen

                  This parameter of the call specifies the time, in milliseconds, that a client connecting to the pipe will wait for when no free pipe instances are available. You can determine how long the client side function will wait before issuing a time-out. It can be a certain time in milliseconds, the default wait time specified by the server, or it can wait forever. Here, the default wait time specified by the server is the key phrase. This time period is determined by the nDefaultTimeOut parameter. Each pipe instance created by CreateNamedPipe must specify the same time-out value. This value is supplied only so that clients, which use WaitNamedPipe or CallNamedPipe functions to connect to the named pipe, know how long they should wait, by default, before issuing a time-out error. If, during this time period, a pipe instance becomes available (the server creates a new instance or some other client disconnects from one pipe instance), then the client-side pipe function will connect to this available pipe. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

                  A Offline
                  A Offline
                  A T I F
                  wrote on last edited by
                  #8

                  Thanks a lot!!! One more question.... LPTSTR lpszPipename = "\\\\.\\pipe\\mynamedpipe"; HANDLE hEvents = CreateEvent(NULL, TRUE, TRUE, NULL); OVERLAPPED Overlap; Overlap.hEvent = hEvents; Pipe.hPipeInst = CreateNamedPipe( lpszPipename, // pipe name PIPE_ACCESS_DUPLEX | // read/write access FILE_FLAG_OVERLAPPED, // overlapped mode PIPE_TYPE_MESSAGE | // message-type pipe PIPE_READMODE_MESSAGE | // message-read mode PIPE_WAIT, // blocking mode INSTANCES, // number of instances BUFSIZE, // output buffer size BUFSIZE, // input buffer size PIPE_TIMEOUT, // client time-out NULL); // no security attributes while (1) { BOOL bSuccess = ::ConnectNamedPipe(m_hPipe, lpOverlapped); dwWait = WaitForMultipleObjects( INSTANCES, // number of event objects hEvents, // array of event objects FALSE, // does not wait for all INFINITE); // waits indefinitely switch(dwWait) { case ..//handle the client.. } } How can I create a new pipe instance using CreateNamedPipe for every new client.

                  A 1 Reply Last reply
                  0
                  • A A T I F

                    Thanks a lot!!! One more question.... LPTSTR lpszPipename = "\\\\.\\pipe\\mynamedpipe"; HANDLE hEvents = CreateEvent(NULL, TRUE, TRUE, NULL); OVERLAPPED Overlap; Overlap.hEvent = hEvents; Pipe.hPipeInst = CreateNamedPipe( lpszPipename, // pipe name PIPE_ACCESS_DUPLEX | // read/write access FILE_FLAG_OVERLAPPED, // overlapped mode PIPE_TYPE_MESSAGE | // message-type pipe PIPE_READMODE_MESSAGE | // message-read mode PIPE_WAIT, // blocking mode INSTANCES, // number of instances BUFSIZE, // output buffer size BUFSIZE, // input buffer size PIPE_TIMEOUT, // client time-out NULL); // no security attributes while (1) { BOOL bSuccess = ::ConnectNamedPipe(m_hPipe, lpOverlapped); dwWait = WaitForMultipleObjects( INSTANCES, // number of event objects hEvents, // array of event objects FALSE, // does not wait for all INFINITE); // waits indefinitely switch(dwWait) { case ..//handle the client.. } } How can I create a new pipe instance using CreateNamedPipe for every new client.

                    A Offline
                    A Offline
                    Antti Keskinen
                    wrote on last edited by
                    #9

                    Named pipes should only be used when you have at least some approximation of how many clients there will be connecting. If you have no idea how many, then I would consider using sockets as a better alternative, for efficiency, safety and listening reasons. Afterall, when the server creates one listening socket, each client can connect to that one and the server will worry about establishing a connection on a seperate socket. But if you must use pipes, then I suggest that you firstly create just one pipe instance. Always when a client connects to this pipe (handle client connecting), the server will call a function that creates a new pipe instance. This follows the logic: "You don't know how many clients there will be, so always keep at least one pipe instance available for a new client." -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

                    A 1 Reply Last reply
                    0
                    • A Antti Keskinen

                      Named pipes should only be used when you have at least some approximation of how many clients there will be connecting. If you have no idea how many, then I would consider using sockets as a better alternative, for efficiency, safety and listening reasons. Afterall, when the server creates one listening socket, each client can connect to that one and the server will worry about establishing a connection on a seperate socket. But if you must use pipes, then I suggest that you firstly create just one pipe instance. Always when a client connects to this pipe (handle client connecting), the server will call a function that creates a new pipe instance. This follows the logic: "You don't know how many clients there will be, so always keep at least one pipe instance available for a new client." -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

                      A Offline
                      A Offline
                      A T I F
                      wrote on last edited by
                      #10

                      Thanks a lot!! I know that the number of clients will be very limited usually max 2, so I think there is not much to worry about....

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups