@@ -0,0 +1,2012 @@
+import socket%0A%0Aclass Server(object):%0A%0A  backlog = 5%0A  client = None%0A%0A  def __init__(self, host, port):%0A    self.socket = socket.socket()%0A    self.socket.bind((host, port))%0A    self.socket.listen(self.backlog)%0A%0A  def __del__(self):%0A    self.close()%0A%0A  def accept(self):%0A    # if a client is already connected, disconnect it%0A    #if self.client:%0A    #  self.client.close()%0A    if self.client is None:%0A        self.client, self.client_addr = self.socket.accept()%0A    return self%0A%0A  def send(self, data):%0A    if not self.client:%0A      raise Exception('Cannot send data, no client is connected')%0A    _send(self.client, data)%0A    return self%0A%0A  def recv(self):%0A    if not self.client:%0A      raise Exception('Cannot receive data, no client is connected')%0A    return _recv(self.client)%0A%0A  def close(self):%0A    if self.client:%0A      self.client.close()%0A      self.client = None%0A    if self.socket:%0A      self.socket.close()%0A      self.socket = None%0A%0Aclass Client(object):%0A%0A  socket = None%0A%0A  def __del__(self):%0A    self.close()%0A%0A  def connect(self, host, port):%0A    self.socket = socket.socket()%0A    self.socket.connect((host, port))%0A    return self%0A%0A  def send(self, data):%0A    if not self.socket:%0A      raise Exception('You have to connect first before sending data')%0A    _send(self.socket, data)%0A    return self%0A%0A  def recv(self):%0A    if not self.socket:%0A      raise Exception('You have to connect first before receiving data')%0A    return _recv(self.socket)%0A%0A  def recvRaw(self):%0A      if not self.socket:%0A          raise Exception('You have to connect first before receiving data')%0A      return _recvRaw(self.socket)%0A%0A  def recv_and_close(self):%0A    data = self.recv()%0A    self.close()%0A    return data%0A%0A  def close(self):%0A    if self.socket:%0A      self.socket.close()%0A      self.socket = None%0A%0Adef _send(socket, data):%0A  socket.sendall(str(data).encode('utf8'))%0A%0Adef _recv(socket):%0A    data = socket.recv(4096)%0A    data = eval(data)%0A    return data%0A%0Adef _recvRaw(socket):%0A    data = socket.recv(4096)%0A    return data%0A

Create Networking.py