File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import socket
2+ import time
3+ import os
4+
5+ server_address = './uds_socket'
6+
7+ # Make sure the socket does not already exist
8+ try :
9+ os .unlink (server_address )
10+ except OSError :
11+ if os .path .exists (server_address ):
12+ raise
13+
14+ sock = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
15+ print ('starting up on {}' .format (server_address ))
16+ sock .bind (server_address )
17+ sock .listen (1 )
18+
19+ while True :
20+ print ('\n waiting for a connection' )
21+
22+ connection , client_address = sock .accept ()
23+ connection .settimeout (300 )
24+
25+ try :
26+ print ('connected' )
27+ connect_time = time .time ()
28+ while True :
29+ try :
30+ data = connection .recv (640 )
31+ if not data :
32+ elapsed_time = int (time .time () - connect_time )
33+ print (f'no data after { elapsed_time } s' )
34+ break
35+ except socket .timeout as exc :
36+ elapsed_time = int (time .time () - connect_time )
37+ print (f'timeout after { elapsed_time } s on recv' )
38+ break
39+ finally :
40+ connection .close ()
You can’t perform that action at this time.
0 commit comments