# Server and Client Abstraction Library

import socket

HOST = "userinterface.local"
PORT = 12345

class Server(object):
	"""A server-serving class"""
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	
	def setup_server(self):
		try:
			Server.s.bind((HOST,PORT))
			print "Bind success"
		except socket.error:
			return "Bind failure"

	def socket_reception(self):
		Server.s.listen(5)
		(connection, address) = Server.s.accept()
		print str(connection)+ " : " + str(address)
		return (connection, address)

	def receive_data(self, connection):
		data = connection.recv(4096)
		return data

	def send_data(self, connection, data):
		connection.send(data)
	
	def close_connection(self, connection):
		connection.close()

class Client(object):
	"""A socket-enabled client class that connects to a server"""
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

	def socket_connection(self):
		Client.s.connect((HOST,PORT))

	def receive_data(self):
		data = Client.s.recv(4096)
		return data

	def send_data(self, data):
		Client.s.send(data)

	def close_connection(self):
		Client.s.close()

@@ -37,23 +37,318 @@
 ary%0A
-%0Aimport socket%0A
+# Code to control common networking functions of the LIDAR project%0A# Uses Python sockets to create connections between Raspberry Pis on local network%0A# Code for both server and client%0A# Author: Matthew Timmons-Brown%0A%0A# Import necessary library for socket control%0Aimport socket%0A%0A# Set constants of communication
 %0AHOS
@@ -492,24 +492,125 @@
 K_STREAM)%0A%09%0A
+%09# Setup server method%0A%09# Tries to bind the server and reports on any errors of server setup process%0A
 %09def setup_s
@@ -732,16 +732,132 @@
 ilure%22%0A%0A
+%09# Socket reception method%0A%09# Listens for incoming connections and creates socket, returning connection and address%0A
 %09def soc
@@ -1020,16 +1020,109 @@
 dress)%0A%0A
+%09# Receive data method%0A%09# Receives data from the connection argument and returns data buffer%0A
 %09def rec
@@ -1188,32 +1188,106 @@
 %0A%09%09return data%0A%0A
+%09# Send data method%0A%09# Sends the data argument to the connection argument%0A
 %09def send_data(s
@@ -1336,16 +1336,73 @@
 data)%0A%09%0A
+%09# Close connection method%0A%09# Closes connection argument%0A
 %09def clo
@@ -1602,189 +1602,522 @@
 )%0A%0A%09
-def socket_connection(self):%0A%09%09Client.s.connect((HOST,PORT))%0A%0A%09def receive_data(self):%0A%09%09data = Client.s.recv(4096)%0A%09%09return data%0A%0A%09def send_data(self, data):%0A%09%09Client.s.send(data)%0A
+# Socket connection method%0A%09# Attempts to connect to the host and port number - kept constant at start of library%0A%09def socket_connection(self):%0A%09%09Client.s.connect((HOST,PORT))%0A%0A%09# Receive data method%0A%09# Receives data from connection and returns it%0A%09def receive_data(self):%0A%09%09data = Client.s.recv(4096)%0A%09%09return data%0A%0A%09# Send data method%0A%09# Sends the data argument to the server%0A%09def send_data(self, data):%0A%09%09Client.s.send(data)%0A%0A%09# Close connection method%0A%09# Closes the connection between the client and the server
 %0A%09de

Comment server/client library