-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
33 lines (24 loc) · 683 Bytes
/
server.py
File metadata and controls
33 lines (24 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import socket
def receive(conn):
"""receive and print messages from connection"""
msg = bytes.decode(conn.recv(1024))
if msg:
print(msg)
if __name__ == "__main__":
socket_addr = "/tmp/docker_socket.s"
# initialize unix socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# bind socket address
if os.path.exists(socket_addr):
os.unlink(socket_addr)
s.bind(socket_addr)
# accept connection
s.listen(2)
conn, addr = s.accept()
print("connection accepted")
# receive messages and print to terminal
while True:
receive(conn)