SHARE
TWEET

Untitled

a guest Oct 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import win32pipe, win32file
  2.  
  3. class PipeServer():
  4.     def __init__(self, pipeName):
  5.         self.pipe = win32pipe.CreateNamedPipe(
  6.         r'\\.\pipe\\'+pipeName,
  7.         win32pipe.PIPE_ACCESS_OUTBOUND,
  8.         win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_WAIT,
  9.         1, 65536, 65536,
  10.         0,
  11.         None)
  12.    
  13.     #Careful, this blocks until a connection is established
  14.     def connect(self):
  15.         win32pipe.ConnectNamedPipe(self.pipe, None)
  16.    
  17.     #Message without tailing '\n'
  18.     def write(self, message):
  19.         win32file.WriteFile(self.pipe, message.encode()+b'\n')
  20.  
  21.     def close(self):
  22.         win32file.CloseHandle(self.pipe)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top