-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
42 lines (31 loc) · 897 Bytes
/
utils.py
File metadata and controls
42 lines (31 loc) · 897 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
34
35
36
37
38
39
40
41
import logging
import socket
import threading
def is_connected_to_host(sock, ip, port):
try:
return sock.getpeername() == (ip, port)
except:
pass
return False
def connect_to_host(sock, ip, port):
if is_connected_to_host(sock, ip, port):
return True
try:
sock.connect((ip, port))
return True
except socket.error as exc:
logging.info("Caught exception socket.error when connecting: %s" % exc)
return False
def get_complement_values_from_list(list1, list2):
return list(set(list1) - set(list2))
def start_new_thread(thread_function, args, daemon):
x = threading.Thread(target=thread_function, args=args, daemon=daemon)
x.start()
return x
def receive_payload(sock, payload_size):
try:
payload = sock.recv(payload_size)
return payload
except:
pass
return bytes()