added sample test files in python and c++ for
linux socket testing
This commit is contained in:
25
linux_socket_test.py
Normal file
25
linux_socket_test.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import socket
|
||||
import os
|
||||
|
||||
SOCKET_FILE = '/tmp/mysocket'
|
||||
|
||||
if os.path.exists(SOCKET_FILE):
|
||||
os.remove(SOCKET_FILE)
|
||||
|
||||
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
server.bind(SOCKET_FILE)
|
||||
server.listen(1)
|
||||
|
||||
print(f"Listening on {SOCKET_FILE}...")
|
||||
|
||||
try:
|
||||
while True:
|
||||
conn, _ = server.accept()
|
||||
data = conn.recv(1024)
|
||||
if data:
|
||||
print("Received:", data.decode())
|
||||
conn.sendall(data) # Echo back
|
||||
conn.close()
|
||||
finally:
|
||||
server.close()
|
||||
os.remove(SOCKET_FILE)
|
||||
Reference in New Issue
Block a user