#!/usr/bin/env python
#
# $Id: wimd.py,v 1.4 2001/11/03 11:05:22 doughellmann Exp $
#
# Copyright 2001 Doug Hellmann.
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""WhackyChat server program
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: wimd.py,v $',
'rcs_id' : '$Id: wimd.py,v 1.4 2001/11/03 11:05:22 doughellmann Exp $',
'creator' : 'Doug Hellmann <doug@hellfly.net>',
'project' : 'PmwContribD',
'created' : 'Sun, 01-Apr-2001 13:24:50 EDT',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.4 $',
'date' : '$Date: 2001/11/03 11:05:22 $',
}
#
# Import system modules
#
import socket
#
# Import Local modules
#
from wimd_defaults import *
from wimd_server import wimd_server,WimdServerError
from CommandLineApp import CommandLineApp
#
# Module
#
class WimdApp(CommandLineApp):
conf_filename = DEFAULT_CONF_FILENAME
def set_conf_file(self, confFileName):
"""
Set the configuration file name. The default
is /etc/wimd.conf.
"""
self.conf_filename = confFileName
return
optionHandler_conf = set_conf_file
optionHandler_c = set_conf_file
def main(self, *args):
self.statusMessage('Creating socket', 2)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.statusMessage('Binding socket to 2980', 2)
sock.bind(('', 2980))
self.statusMessage('Creating server', 2)
server = wimd_server(sock,
conf_filename=self.conf_filename)
self.statusMessage('Listening', 2)
server.listen(1)
server.loop()
return
if __name__ == '__main__':
try:
WimdApp().run()
except socket.error, msg:
if msg.args[0] == 98:
# Already in use
print 'Could not bind to server socket because another process'
print 'already has the socket bound.'
else:
print 'Could not start server.'
print msg
except CommandLineApp.HelpRequested:
pass
|