37 lines
739 B
Python
37 lines
739 B
Python
#!/usr/bin/env python3.5
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Basic send & receive functions for socket usage.
|
|
"""
|
|
|
|
|
|
__authors__ = "HorlogeSkynet"
|
|
__copyright__ = "Copyright 2017, ACMS"
|
|
__license__ = "GPLv3"
|
|
__version__ = "0.1.0"
|
|
__status__ = "Development"
|
|
__date__ = "03/03/2017"
|
|
|
|
|
|
# Our buffer length for data sent and received
|
|
BUFFER_SIZE = 2048
|
|
|
|
|
|
def sendData(connection, data):
|
|
try:
|
|
connection.send(data.encode())
|
|
|
|
except:
|
|
print("An error occurred on the connection with a client, let\'s close its socket.")
|
|
connection.close()
|
|
|
|
|
|
def recvData(connection):
|
|
try:
|
|
return connection.recv(BUFFER_SIZE).decode().strip()
|
|
|
|
except:
|
|
print("An error occurred on the connection with a client, let\'s close its socket.")
|
|
connection.close()
|