Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement