예제 #1
0
def get_server():
    """
    Returns a valid server, worker, username tuple
    Note this isn't quite a perfectly even distribution but it 
    works well enough
    """
    return _select(list(generate_tuples(ServerLogic.get_server())))
예제 #2
0
def get_server():
    """
    Returns a valid server, worker, username tuple
    Note this isn't quite a perfectly even distribution but it 
    works well enough
    """
    return _select(list(generate_tuples(ServerLogic.get_server())))
예제 #3
0
    def OnStartBtnPressed(self, event):
        self.port = int (string.atoi(self.portSlot.GetValue()) )
        self.Log("Try start server...")
        self.LogAdd("IP: " + str(self.ip) + " @: " + str(self.port))
        
        self.server = Server(self)

        self.t = threading.Thread(target = self.server.run, args = ())
        self.t.daemon = True
        self.t.start()

        self.serverLogic = ServerLogic()
        self.serverLogic.setLog(self.LogAdd)
        self.start()
예제 #4
0
class MyMainFrame(wx.Frame):
    def __init__(self):
        self.tcpServ = None
        # self.ip = self.GetMyIP()
        self.ip = self.GetLocalIP();
        self.port = 9101
        wx.Frame.__init__(self, None, -1, "Bug Server",
            size = (300,550),
            style = wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
        panel = wx.Panel(self)
        
        ipLab = wx.StaticText(panel, -1, "IP Address:", pos = (10,10))
        ipSlot = wx.TextCtrl(panel, -1, self.ip, 
                pos = (70, 10), size=(125, -1))
        
        portLab = wx.StaticText(panel, -1, "port:", pos = (200,10))     
        self.portSlot = wx.TextCtrl(panel, -1, str(self.port), 
                pos = (230, 10), size=(45, -1))
        
        
        startServerBtn = wx.Button(panel, -1, "Start Server", pos = (50, 40))
        self.Bind(wx.EVT_BUTTON, self.OnStartBtnPressed , startServerBtn)

        stopServerBtn = wx.Button(panel, -1, "Stop Server", pos = (150, 40))
        self.Bind(wx.EVT_BUTTON, self.OnStopBtnPressed , stopServerBtn)

        startClientBtn = wx.Button(panel, -1, "Start", pos = (50, 70))
        self.Bind(wx.EVT_BUTTON, self.OnStartClientBtnPressed , startClientBtn)

        stopClientBtn = wx.Button(panel, -1, "Stop", pos = (150, 70))
        self.Bind(wx.EVT_BUTTON, self.OnStopClientBtnPressed , stopClientBtn)


        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self.log = wx.TextCtrl(panel, -1,
               "",
               pos = (10,100), size=(280, 400), style=wx.TE_MULTILINE) 

    def Log(self,str ):
        self.log.Clear()
        self.log.write(str + "\n")
    
    def LogAdd(self,str):
        self.log.write(str + "\n")        
    
    def OnStartBtnPressed(self, event):
        self.port = int (string.atoi(self.portSlot.GetValue()) )
        self.Log("Try start server...")
        self.LogAdd("IP: " + str(self.ip) + " @: " + str(self.port))
        
        self.server = Server(self)

        self.t = threading.Thread(target = self.server.run, args = ())
        self.t.daemon = True
        self.t.start()

        self.serverLogic = ServerLogic()
        self.serverLogic.setLog(self.LogAdd)
        self.start()
    
    def OnStopBtnPressed(self, event):
        self.server.stop()

    def OnStartClientBtnPressed(self, event):
        pass

    def OnStopClientBtnPressed(self, event):
        pass
    
    def OnCloseWindow(self,event):
        print 'destbuffer_sizeroy'

        self.Destroy()
    
    def GetMyIP(self):
        ip = re.search('\d+\.\d+\.\d+\.\d+',Popen('ipconfig', stdout=PIPE).stdout.read()).group(0)  
        print ip
        return ip

    def GetLocalIP(self):
        try:
            csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            csock.connect(('8.8.8.8', 80))
            (addr, port) = csock.getsockname()
            csock.close()
            return addr
        except socket.error:
            return "127.0.0.1"