コード例 #1
0
ファイル: Server.py プロジェクト: shivamchoudhary/w4119
 def __init__(self, port):
     """
     host can be specified in config.json file
     """
     self.host = configuration['host']
     self.port = port
     self.userpasswd = Common.load_password(
             configuration['location']['passwdf'])
     serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     try:
         serversocket.bind((self.host, self.port))
     except socket.error as error:
         logging.critical("Socket binding failed with error %s", error)
         sys.exit(0)
     serversocket.listen(5)
     logger.debug("Server Running")
     while True:
         (clientsocket, clientaddress) = serversocket.accept()
         logger.info("Starting New Thread for IP:%s and socket %s",
                 clientaddress, clientsocket)
         thread = threading.Thread(target=handlerequests, args=(clientsocket,
             clientaddress))
         thread.deamon = True
         thread.start()
コード例 #2
0
ファイル: Server.py プロジェクト: shivamchoudhary/w4119
#! /usr/bin/python
import sys
import socket
import Common
import os
import threading
import time
import logging
logger = logging.getLogger()
FORMAT = "[%(levelname)s:%(threadName)-10s] %(message)s" 
logging.basicConfig(format=FORMAT)
logger.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler()
logger.addHandler(consoleHandler)
configuration = Common.read_config()
userpasswd = Common.load_password(configuration['location']['passwdf'])
block_time = configuration['BLOCK_TIME']
numfailattempt = configuration['NUMFAILATT']
blocked_user = []
logged_user  = {}
auth_users = []
client_sockets =[]
user_clientmap = {}
return_status = configuration["return_status"]

class CreateServer(object):
    """
    Creates a server on localhost at specifed port.
    """
    def __init__(self, port):
        """