vcs-python-repository/Server/PipeServer/main.py
2024-04-26 22:11:53 -07:00

37 lines
985 B
Python

import win32pipe
import win32file
from handle_connection import handle_connection
# Function to create named pipe server
def create_named_pipe_server(pipe_name):
print(f"Named pipe server started: {pipe_name}")
while True:
try:
# Create named pipe
pipe = win32pipe.CreateNamedPipe(
fr'\\.\pipe\{pipe_name}',
win32pipe.PIPE_ACCESS_DUPLEX,
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT,
1, 65536, 65536,
0,
None
)
win32pipe.ConnectNamedPipe(pipe, None)
handle_connection(pipe)
finally:
win32file.CloseHandle(pipe)
# Main function
if __name__ == "__main__":
# Define the name of the named pipe
pipe_name = "example_pipe"
# Create and start the named pipe server
create_named_pipe_server(pipe_name)
# Wait for user input to exit
input("Press Enter to exit...")