Click here to Skip to main content
15,927,514 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generaleditable listctrl Pin
DanYELL23-Jun-04 13:08
DanYELL23-Jun-04 13:08 
GeneralRe: editable listctrl Pin
Anthony_Yio23-Jun-04 16:44
Anthony_Yio23-Jun-04 16:44 
QuestionA better System( ... ) call? Pin
mike-o23-Jun-04 12:37
mike-o23-Jun-04 12:37 
AnswerRe: A better System( ... ) call? Pin
Johan Rosengren23-Jun-04 21:32
Johan Rosengren23-Jun-04 21:32 
GeneralRe: A better System( ... ) call? Pin
mike-o24-Jun-04 5:29
mike-o24-Jun-04 5:29 
GeneralInterpreting strings as packed binary data Pin
NizZy23-Jun-04 12:18
NizZy23-Jun-04 12:18 
GeneralRe: Interpreting strings as packed binary data Pin
NizZy23-Jun-04 12:28
NizZy23-Jun-04 12:28 
Generalnamed pipe problem Pin
pnpfriend23-Jun-04 11:20
pnpfriend23-Jun-04 11:20 
Hello All, I'm writing client/server programs using named pipe.
In the server program,
when the user click on a button, it create a thread. Inside a thread function, CreatePipe is called first then listen to client.

Here the code how server program creates the pipe and the thread function
<br />
UINT theThreadFunction(LPVOID lParam)<br />
{<br />
 ServerApp *s = (ServerApp*)lParam;<br />
 s->CreatePipe();<br />
while(!stop)<br />
{<br />
 s->CommunicateWithClient();<br />
}<br />
}<br />
<br />
void ServerApp::CreatePipe()<br />
{<br />
CString temp = "\\\\.\\pipe\\Server";	<br />
LPCTSTR lpszPipename = (const char*) temp;<br />
<br />
 hPipe = CreateNamedPipe( <br />
	   lpszPipename,             // pipe name <br />
	   PIPE_ACCESS_DUPLEX,       // read/write access <br />
	   PIPE_TYPE_MESSAGE |       // message type pipe <br />
	   PIPE_READMODE_MESSAGE |   // message-read mode <br />
	   PIPE_WAIT,                // blocking mode <br />
	   PIPE_UNLIMITED_INSTANCES, // max. instances  <br />
	   BUFSIZE,                  // output buffer size <br />
	   BUFSIZE,                  // input buffer size <br />
	   NMPWAIT_USE_DEFAULT_WAIT, // client time-out <br />
	   NULL);                    // no security attribute <br />
if (hPipe == INVALID_HANDLE_VALUE) <br />
   {<br />
	   MessageBox("CreatePipe failed"); <br />
	   enableDlgItems = true;		   <br />
	   return ;<br />
   }  <br />
}<br />
<br />
void ServerApp::CommunicateWithClient()<br />
{<br />
  ...<br />
  bool fConnected = ConnectNamedPipe(hPipe, NULL);// ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); <br />
...<br />
}<br />

The client application get executed before the Server Application gets executed.
The client used the following code.
<br />
bool ClientApp::ConnectToServer( HANDLE &hPipe)<br />
{<br />
 LPCTSTR lpszPipename = "\\\\serverComputerName\\pipe\\Server";<br />
	bool connected = false;<br />
       hPipe = CreateFile( <br />
         lpszPipename,   // pipe name <br />
         GENERIC_READ |  // read and write access <br />
         GENERIC_WRITE, <br />
         0,              // no sharing <br />
         NULL,           // no security attributes<br />
        OPEN_EXISTING,  // opens existing pipe <br />
         0,              // default attributes <br />
         NULL);          // no template file <br />
if (hPipe != INVALID_HANDLE_VALUE) <br />
	  {<br />
		 connected = true;<br />
         break; <br />
	  }<br />
return connected;<br />
 }<br />


Here the problem, the ServerApp CreateNamedPipe() and then called ConnectNamedPipe(). If there isn't a client connect to the same pipe, the ConnectNamedPipe() waits until a client get connected.

The client Application called CreateFile() to connect to the pipe the server opened,
and return was return connected = true. However in the ServerApp, ConnectNamedPipe() is still waiting for the client to connnect.

Why the ServerApp stills think there isn't a client connecting to the pipe even though the CreateFile() in the ClientApp is successfully connected to named pipe?

Thank you
GeneralNeed Map to Database Ideas Pin
macbeth7623-Jun-04 10:20
macbeth7623-Jun-04 10:20 
GeneralRe: Need Map to Database Ideas Pin
Anthony_Yio23-Jun-04 16:38
Anthony_Yio23-Jun-04 16:38 
GeneralChanging fontcolor Pin
Wim Summer23-Jun-04 9:42
sussWim Summer23-Jun-04 9:42 
GeneralRe: Changing fontcolor Pin
bneacetp23-Jun-04 10:04
bneacetp23-Jun-04 10:04 
GeneralChanging the fontcolor. Pin
Wim Summer23-Jun-04 9:37
sussWim Summer23-Jun-04 9:37 
GeneralRe: Changing the fontcolor. Pin
User 58385223-Jun-04 19:11
User 58385223-Jun-04 19:11 
GeneralProblems with Bitmaps Pin
Member 114074823-Jun-04 9:29
Member 114074823-Jun-04 9:29 
GeneralRe: Problems with Bitmaps Pin
PJ Arends23-Jun-04 10:21
professionalPJ Arends23-Jun-04 10:21 
GeneralRe: Problems with Bitmaps Pin
Member 114074823-Jun-04 11:06
Member 114074823-Jun-04 11:06 
GeneralLPDISPATCH help me Pin
Nitro_gen23-Jun-04 9:16
Nitro_gen23-Jun-04 9:16 
GeneralRe: LPDISPATCH help me Pin
Anthony_Yio23-Jun-04 16:33
Anthony_Yio23-Jun-04 16:33 
GeneralSetting a Custom Background for the Main Menu Bar Pin
Steve Thresher23-Jun-04 9:13
Steve Thresher23-Jun-04 9:13 
GeneralWant help in learning Unicode Usage Pin
Member 119592223-Jun-04 8:53
Member 119592223-Jun-04 8:53 
GeneralString formatting question Pin
Nick Parker23-Jun-04 8:49
protectorNick Parker23-Jun-04 8:49 
GeneralRe: String formatting question Pin
palbano23-Jun-04 8:59
palbano23-Jun-04 8:59 
GeneralRe: String formatting question Pin
Nick Parker23-Jun-04 9:17
protectorNick Parker23-Jun-04 9:17 
GeneralRe: String formatting question Pin
PJ Arends23-Jun-04 10:34
professionalPJ Arends23-Jun-04 10:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.