示例#1
0
 def handle_connect(self, widget):
     """ 
         handle a click on Session->Connect 
     """
     self.ping_timeout = 0
     self.sock.close()
     self.sock = Connection()
     self.sock.connect()
     self.textview.insert("Connected.", 'green')
示例#2
0
    def __init__(self):
        ## Make a gtk builder
        b = gtk.Builder()
        b.add_from_file('janus-0.6.glade')
        
        ## auto connect signals
        b.connect_signals(self)
        
        ## Get Windows
        self.window = b.get_object("main_window")
        self.test_window = b.get_object("test_window")
        self.about_window = b.get_object("about_window")
                
        ## Get Widgets
        self.info_bar = InfoBar()
        b.get_object("info_bar").add(self.info_bar)

        ## input
        self.entry = FancyInput() 
        b.get_object("main_input_frame").add(self.entry)

        ## Map
        self.map = Map()
        b.get_object('map_box').add(self.map)

        ## Contents
        self.contents = RoomContents()
        b.get_object('contents').add(self.contents.treeview)
        self.contents.idle()

        ## Spellbar
        b.get_object('spellbar').add(SpellBar())

        ## Textview
        self.textview = AutoScrolledTextView()        
        b.get_object("scrolled_window").add(self.textview)       

        ## Connect up events
        self.window.connect("delete_event", delete_event)        
        self.entry.connect("entry-send", self.send)
        
        ## Show Windows that need it.
        self.window.show_all()

        ## Focus the entry box
        self.entry.grab_focus()

        ## Setup socket
        self.sock = Connection()
        gobject.timeout_add(10, self.poll)
示例#3
0
def make_connections(number):
    print "connecting ", len(connections), num_in
    for n in xrange(number):
        con = Connection(address='127.0.0.1')
        con.connect()
        connections.append(con)
示例#4
0
from sock import Connection
from bot import Bot
import threading

# other_bot = Bot("irc.freenode.net", "#tagprobots", "other_bot", 6667)
second_bot = Bot("irc.freenode.net", "#tagprobots", "other_other_bot", 6666)
danny_bot = Bot("hephaestos.me", "#main", "great_bot", 6668)

danny_sock = Connection(danny_bot)
danny_sock.connect()


# socky = Connection(other_bot)
# socky.connect()

# socky2 = Connection(second_bot)
# socky2.connect()


while 1:
	# message = socky.receive()
	# other_bot.respond(socky, message)

	message = danny_sock.receive()
	danny_bot.respond(danny_sock, message)


	# message2 = socky2.receive()


示例#5
0
from sock import Connection
from time import sleep

connections = []

for n in range(8000):
    con = Connection(address='127.0.0.1')
    con.connect()
    connections.append(con)
    print n, len(connections)
    sleep(0.01)
示例#6
0
class Client:
    def __init__(self):
        ## Make a gtk builder
        b = gtk.Builder()
        b.add_from_file('janus-0.6.glade')
        
        ## auto connect signals
        b.connect_signals(self)
        
        ## Get Windows
        self.window = b.get_object("main_window")
        self.test_window = b.get_object("test_window")
        self.about_window = b.get_object("about_window")
                
        ## Get Widgets
        self.info_bar = InfoBar()
        b.get_object("info_bar").add(self.info_bar)

        ## input
        self.entry = FancyInput() 
        b.get_object("main_input_frame").add(self.entry)

        ## Map
        self.map = Map()
        b.get_object('map_box').add(self.map)

        ## Contents
        self.contents = RoomContents()
        b.get_object('contents').add(self.contents.treeview)
        self.contents.idle()

        ## Spellbar
        b.get_object('spellbar').add(SpellBar())

        ## Textview
        self.textview = AutoScrolledTextView()        
        b.get_object("scrolled_window").add(self.textview)       

        ## Connect up events
        self.window.connect("delete_event", delete_event)        
        self.entry.connect("entry-send", self.send)
        
        ## Show Windows that need it.
        self.window.show_all()

        ## Focus the entry box
        self.entry.grab_focus()

        ## Setup socket
        self.sock = Connection()
        gobject.timeout_add(10, self.poll)
        
    
    def ping(self):
        if self.ping_timeout:
            try:
                self.sock.send('ping')
                return True
            except:
                return False
        else:
            return False
            
    def handle_connect(self, widget):
        """ 
            handle a click on Session->Connect 
        """
        self.ping_timeout = 0
        self.sock.close()
        self.sock = Connection()
        self.sock.connect()
        self.textview.insert("Connected.", 'green')
                
    def handle_disconnect(self, widget):
        """ 
            handle a click on Session-Disconnect 
        """
        self.sock.close()
        self.textview.insert("You have been disconnected.", 'yellow')
        self.ping_timeout = 0
        
    def handle_close(self, widget):
        """
            handle a click on Session-Close
        """ 
        gtk.main_quit()
        return False
            
    def send(self, widget, text):
        """ 
            a callback for events wanting to write to the socket
        """
        #report to textview
        try:
            self.sock.send(text)
        except socket.error:
            self.textview.insert("You are not connected.", 'yellow')
    def handle_about(self, widget):
        self.about_window.show_all()
           
    
    def poll(self):
        """
            poll the socket and see if there is any data to be processed.
            if so, loop through the packets and process all of it before 
            the next loop.
        """
        if self.sock.read():
            messages = []
            while self.sock.read():
                messages.append(self.sock.get_packet())
            for m in messages:
                parse_packet(self, m)
            self.sock.buf = ''
        return True

    def start_pings(self):
        pass#self.ping_timeout = gobject.timeout_add(6000, self.ping)