Last active
October 3, 2019 15:31
-
-
Save Coronon/6c6ef55bdccefab18779a8cef2ec3c97 to your computer and use it in GitHub Desktop.
Easy NamedPipe for Windows written in python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32pipe, win32file | |
class PipeServer(): | |
def __init__(self, pipeName): | |
self.pipe = win32pipe.CreateNamedPipe( | |
r'\\.\pipe\\'+pipeName, | |
win32pipe.PIPE_ACCESS_OUTBOUND, | |
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_WAIT, | |
1, 65536, 65536, | |
0, | |
None) | |
#Careful, this blocks until a connection is established | |
def connect(self): | |
win32pipe.ConnectNamedPipe(self.pipe, None) | |
#Message without tailing '\n' | |
def write(self, message): | |
win32file.WriteFile(self.pipe, message.encode()+b'\n') | |
def close(self): | |
win32file.CloseHandle(self.pipe) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment