Download - Interprocee Communication
-
8/6/2019 Interprocee Communication
1/21
Interprocess CommunicationInterprocess Communication
2007/06/06
-
8/6/2019 Interprocee Communication
2/21
Agenda Agenday Introductiony A nonymous pipesy
Named pipesy Mailslots
2
-
8/6/2019 Interprocee Communication
3/21
IntroductionIntroductiony Perform directly process-to-process
communicationy Relative A PI:
Readfile() and Writefile()
3
-
8/6/2019 Interprocee Communication
4/21
A nonymous pipes A nonymous pipes
4
-
8/6/2019 Interprocee Communication
5/21
-
8/6/2019 Interprocee Communication
6/21
-
8/6/2019 Interprocee Communication
7/21
Exercise 1Exercise 1y Please refer to Fi gure 11-1 and
Pro gram 11-1, and them finish them.Pro gram 11-1 create pipe and you stillneed to create Pro gram 1 and Pro gram2
7
-
8/6/2019 Interprocee Communication
8/21
Named pipesNamed pipes
8
-
8/6/2019 Interprocee Communication
9/21
-
8/6/2019 Interprocee Communication
10/21
Win32 A PI Win32 A PI
10
Server:
H A NDLE Create N amedPipe (LPCTSTR lpPipeName,DWORD dwOpenMode,DWORD dwPipeMode,
DWORD nMaxInstance,DWORD cbOutBuf,DWORD cdInBuf,DWORD dwTimeout,LPSECURITY_ A TTRIBUT ES lpsa,
);
BOOL Connect N amedPipe (H A NDLE hNamedPipe,LPOV ERL A PP ED lpOverlapped,
);
BOOL Disconnect N amedPipe (H A NDLE hNamedPipe,
);
Client:
BOOL Wait N amedPipe (LPCTSTR lpPipeName,DWORD dwTimeout,
);
The format for pipe name\\ .\ pipe \[ path]pipename\\ servername \ pipe \[ path]pipe
name
-
8/6/2019 Interprocee Communication
11/21
-
8/6/2019 Interprocee Communication
12/21
A dvanced function A dvanced functiony To instead of WriteFile() and
ReadFiled()T ransact N amedPipe()x
First convenientx Create permanent connect that causelimited number of clients
Call N amedPipe()x Second convenientx Create temporary connectionx Is uses to specify the pipe, and set a
time-out period
12
Combine :CreateFile() WriteFile()
ReadFile()CloaseHandle()
-
8/6/2019 Interprocee Communication
13/21
Compare anonymous pipe andCompare anonymous pipe andnamed pipenamed pipe
Duplex half-duplex full-duplex
Data unit Character-based Character-based/messa ge based
IndependentInstance No Yes
Location One the samecomputer
On the samecomputer or different
computers
Set security Yes Yes13
-
8/6/2019 Interprocee Communication
14/21
Exercise 2Exercise 2y Please refer to pro gram 11-2, and write
a simple named pipe that can support10 client to connect.
Usin g CallNamedPipe()
14
-
8/6/2019 Interprocee Communication
15/21
-
8/6/2019 Interprocee Communication
16/21
CharacteristicsCharacteristicsy Broadcast mechanismy One-directionaly Can have multiple writers and readers, but often
is one-to-many y Can be located over a network domainy Client writes and server readsy Only one specific mailslot name can exist on the
same machine
16
-
8/6/2019 Interprocee Communication
17/21
How to useHow to use mailslotsmailslots
y Server(Reader)Creates a mailslot handle withCreateMail S lot() .
Then waits to receive a mailslotmessa ge with a R eadFile() call
y Client(Writer)A w rite-only client open the
mailslot with CreateFile() Write messa ges with WriteFile()
17
-
8/6/2019 Interprocee Communication
18/21
18
Server (CreateMailslot) \\.\mailslot\
Client(CreateFile)\\*\ mailslot \ mailslotname\\< computername> \ mailslot \ mailslot name\\< domainname> \ mailslot \ mailslotname\\.\ mailslot \ mailslotname
-
8/6/2019 Interprocee Communication
19/21
Compare named pipes andCompare named pipes and mailslotsmailslots
19
N amed pipe Mailslots
Client Server Client Server
NamedPipeHandle orConnection
CreateFileCallNamedPipe,TransactNamedPipe
CreateNamedPipe CreateFile CreateMailslot
A ction Read/write Read/write Write Read
NoteConnection oriented Can broadcast
-
8/6/2019 Interprocee Communication
20/21
Exercise 3Exercise 3y Try to create a mailslot between two
computers, and remember to useGetMailslotInfo () to check themailslot status.
y If you create a mailslot name that is AAA , but these already exists thesame name on the same computer. What is the error code if you use
GetLast Error() to retrieve it .
20
-
8/6/2019 Interprocee Communication
21/21
21