2 # SPDX-License-Identifier: GPL-2.0
5 # This file is part of Lustre, http://www.lustre.org/
7 # lustre/tests/socketclient
9 # Domain socket client, used to test that domain sockets
12 # Rewrite in Python: Timothy Day <timday@amazon.com>
20 # Define a function for logging messages
22 print(f"{sys.argv[0]} {os.getpid()}: {msg} at {os.popen('date').read().strip()}")
25 # Get the socket path from the command-line argument,
26 # or ask the user to input one
28 socket_path = sys.argv[1]
30 socket_path = input("Enter socket path: ")
33 # Create a Unix domain socket
34 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
36 # Connect to the specified rendezvous point
37 sock.connect(socket_path)
39 logmsg(f"connection on {socket_path}")
42 # Receive data from the socket in chunks of 1024 bytes
43 data = sock.recv(1024)
45 # If there's no more data to read, exit the loop
49 # Decode the data as UTF-8 and print it to the standard output
50 print("Message:", data.decode('utf-8'), end='')
52 except socket.error as e:
53 logmsg(f"Socket error: {e}")