#!/usr/bin/python
#
# commProcto.py
# 
# encapulates basic socket methods needed to talk to a
# ProctoLogic server (http://galatea.stetson.edu/~ProctoLogic/)
#
# author michael branton
#
# This script is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this script; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import socket

# create a socket to communicate on
def create(port):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	if port!=0:
        	s.bind(("",port))
        return s

# send data out
def send(s,host, port, message):
        HOST = host
        PORT = port
        s.sendto(message, (HOST, PORT))

# get data back
def receive(s):
        result = s.recvfrom(1024)
        return result
