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 Client Support Server Application designed with Named Pipes hangs frequently

Multiple Client Support Server Application designed with Named Pipes hangs frequently

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmin
2 Posts 2 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.
  • S Offline
    S Offline
    SRIVATHSAN VIJAYA
    wrote on last edited by
    #1

    Initially we have designed a client server model with named pipes. Where Server is capable of handling only one client. We expanded the server to hold 4 client instances at a time. After which application hangs frequently while connection is established between client and Server. Added the code snippet below. Please look at the snippet and suggest Is it a right method to handle multiple clients. //Client.c rhPipe = CreateFile("\\\\.\\Pipe\\Send", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(rhPipe == INVALID_HANDLE_VALUE) { rhPipe = NULL; return; } whPipe = CreateFile("\\\\.\\Pipe\\Recv", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(whPipe == INVALID_HANDLE_VALUE) { whPipe = NULL; return; } char message[512]; char buffer[1024]; BOOL writeStatus = FALSE; BOOL bResult = FALSE; DWORD cbBytes = 0; COMMTIMEOUTS cto; cto.ReadIntervalTimeout = 5; cto.ReadTotalTimeoutConstant = 5*1000; SetCommTimeouts(rhPipe, &cto); while(1) { memset(message,0,sizeof(message)); strcpy(message,"Message From Client.... !!!"); writeStatus = FALSE; cbBytes = 0; writeStatus = WriteFile(whPipe, message, sizeof(message), &cbBytes, NULL); if(writeStatus == FALSE || cbBytes != sizeof((message)) { return; } memset(&buffer,0,sizeof(buffer)); bResult = ReadFile(rhPipe, &buffer, 1024, &cbBytes, NULL); if(bResult == TRUE) { if(cbBytes == 0 ) printf("Receive from Pipe Timeout.... \n"); else { printf("Data Received From Server...: %s\n,buffer); } } else { if(GetLastError() != 0) { CloseHandle(rhPipe); CloseHandle(whPipe); return; } } } //Server.c typedef struct { OVERLAPPED oOverlap; HANDLE hPipeInst; CHAR chRequest[BUFFER_SIZE]; DWORD cbRead; TCHAR chReply[BUFFER_SIZE]; DWORD cbToWrite; DWORD dwState; BOOL fPendingIO; int processId; } PIPEINST, *LPPIPEINST; #define RECEIVING_PIPE 0 #define TRANSMITTING_PIPE 1 #define INSTANCES 4 PIPEINST Pipe[INSTANCES]; HANDLE hEvents[INSTANCES]; int CreateIPCPipe(int option) { char log_buf[512]; switch(option) { case RECEIVING_PIPE: { int i; for (i = 0; i < INSTANCES; i++) { hEvents[i] = CreateEvent(NULL,TRUE,FALSE, NULL); if (hEvents[i] == NULL) { return 0; } Pipe[i].oOverlap.hEvent = hEvents[i]; Pipe[i].hPipeInst = CreateNamedPipe("\\\\.\\Pipe\\Recv", PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PI

    L 1 Reply Last reply
    0
    • S SRIVATHSAN VIJAYA

      Initially we have designed a client server model with named pipes. Where Server is capable of handling only one client. We expanded the server to hold 4 client instances at a time. After which application hangs frequently while connection is established between client and Server. Added the code snippet below. Please look at the snippet and suggest Is it a right method to handle multiple clients. //Client.c rhPipe = CreateFile("\\\\.\\Pipe\\Send", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(rhPipe == INVALID_HANDLE_VALUE) { rhPipe = NULL; return; } whPipe = CreateFile("\\\\.\\Pipe\\Recv", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(whPipe == INVALID_HANDLE_VALUE) { whPipe = NULL; return; } char message[512]; char buffer[1024]; BOOL writeStatus = FALSE; BOOL bResult = FALSE; DWORD cbBytes = 0; COMMTIMEOUTS cto; cto.ReadIntervalTimeout = 5; cto.ReadTotalTimeoutConstant = 5*1000; SetCommTimeouts(rhPipe, &cto); while(1) { memset(message,0,sizeof(message)); strcpy(message,"Message From Client.... !!!"); writeStatus = FALSE; cbBytes = 0; writeStatus = WriteFile(whPipe, message, sizeof(message), &cbBytes, NULL); if(writeStatus == FALSE || cbBytes != sizeof((message)) { return; } memset(&buffer,0,sizeof(buffer)); bResult = ReadFile(rhPipe, &buffer, 1024, &cbBytes, NULL); if(bResult == TRUE) { if(cbBytes == 0 ) printf("Receive from Pipe Timeout.... \n"); else { printf("Data Received From Server...: %s\n,buffer); } } else { if(GetLastError() != 0) { CloseHandle(rhPipe); CloseHandle(whPipe); return; } } } //Server.c typedef struct { OVERLAPPED oOverlap; HANDLE hPipeInst; CHAR chRequest[BUFFER_SIZE]; DWORD cbRead; TCHAR chReply[BUFFER_SIZE]; DWORD cbToWrite; DWORD dwState; BOOL fPendingIO; int processId; } PIPEINST, *LPPIPEINST; #define RECEIVING_PIPE 0 #define TRANSMITTING_PIPE 1 #define INSTANCES 4 PIPEINST Pipe[INSTANCES]; HANDLE hEvents[INSTANCES]; int CreateIPCPipe(int option) { char log_buf[512]; switch(option) { case RECEIVING_PIPE: { int i; for (i = 0; i < INSTANCES; i++) { hEvents[i] = CreateEvent(NULL,TRUE,FALSE, NULL); if (hEvents[i] == NULL) { return 0; } Pipe[i].oOverlap.hEvent = hEvents[i]; Pipe[i].hPipeInst = CreateNamedPipe("\\\\.\\Pipe\\Recv", PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PI

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please edit your question and format your code properly by using the code button above the edit box, or add <pre></pre> tags around it. you also need to indicate where in the code things are going wrong.

      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