当前位置: 首页>>代码示例>>Python>>正文


Python Network.send方法代码示例

本文整理汇总了Python中network.Network.send方法的典型用法代码示例。如果您正苦于以下问题:Python Network.send方法的具体用法?Python Network.send怎么用?Python Network.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在network.Network的用法示例。


在下文中一共展示了Network.send方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Webserver

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import send [as 别名]
class Webserver(object):

    def __init__(self):
        cherrypy.engine.subscribe('stop', self.stop)
        self.net = Network(WEBSERVER_IP, WEBSERVER_PORT)
        # spusti se pri zapinani


    def stop(self):
        # spusti se pri vypinani
        pass

    @cherrypy.expose
    def index(self):
        # exposed metoda -- zavolali jsme /
        return base.render()

    def doit(self, action, value):
        # spustit ledky
        data = dict()
        data["key"] = action
        data["value"] = value
        self.net.send(data, SERVER_IP, SERVER_PORT)

    @cherrypy.expose
    def set(self, value):
        self.doit("set", value)
        return self.index()

    @cherrypy.expose
    def get(self, value):
        self.doit("get", value)
        tmp = self.net.recv()
        # should be recv
        return tmp
开发者ID:fialakarel,项目名称:haut-webserver,代码行数:37,代码来源:haut-webserver.py

示例2: WorkclipMini

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import send [as 别名]
class WorkclipMini(object):
  #===============================
  def __init__(self):
    self.clipboard = anyos.Clipboard()
    self.hotkey = anyos.Hotkey()
    louie.connect(self.on_hotkey, self.hotkey.event)
    self.network = Network('192.168.0.255', 45644)
    louie.connect(self.on_command, self.network.command)
    
    self.hotkey.add_bind('CLIPBOARD', '<control><alt>C')
    self.hotkey.add_bind('URL', '<control><alt>B')    
    
    chrome = os.path.join(os.environ.get('LOCALAPPDATA') or '', 'Google\\Chrome\\Application\\chrome.exe')
    extra_browsers = [chrome, 'chrome.exe']
    for browser in extra_browsers:
      if webbrowser._iscommand(browser):
        webbrowser.register(browser, None, webbrowser.BackgroundBrowser(browser), -1)
    
  #===============================
  def run(self):
    thread = threading.Thread(target=self.loop)
    thread.start()
    self.hotkey.loop()
  
  #===============================
  def on_command(self, command, **kwargs):
    command = command.split(' ', 1)
    
    if command[0] == 'CLIPBOARD':
      self.clipboard.text = command[1]
    elif command[0] == 'URL':
      webbrowser.open_new_tab(command[1])
      
  #===============================
  def on_hotkey(self, name, **kwargs):
    self.clipboard.copy_selected_text()
    text = self.clipboard.text
    
    if name == 'CLIPBOARD':
      for address in self.network.addresses:
        self.network.send(address, name, text)
    elif name == 'URL':
      urls = re.findall(r'(([a-zA-Z]+://)?(www.)?[^ ]+\.[^ \n\r]{2,})', text, re.IGNORECASE)
      if not urls:
        urls = [[text,],]
        
      for url in urls:
        for address in self.network.addresses:
          self.network.send(address, name, url[0])

  #===============================
  def loop(self):    
    reactor.listenUDP(45644, self.network)
    refresh = task.LoopingCall(self.network.refresh_list)
    refresh.start(30) # Refresh list at rate defined in config.py
    reactor.run(False)
开发者ID:kdar,项目名称:workclipmini,代码行数:58,代码来源:workclipmini.py

示例3: Brain

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import send [as 别名]
class Brain(object):
    
    def __init__(self):
        self.mem = Mem()
        self.cmd = Cmd()
        self.net = Network()
        
        self.ifttt = open("./brain/logic/IFTTT.py").read()
        
        pass
    
    def process(self, data, ip):
        # process request from client
        print(str(datetime.now()) + " " + str(self.net.gethost(ip[0])) + ":" + str(ip[1]) + " " + str(data))
        self.mem.setmem(str(self.net.gethost(ip[0])) + "_" + str(data["key"]), str(data["value"]))
        
        host=str(self.net.gethost(ip[0]))        
        
        # if this than this
        exec(self.ifttt)


    def run(self):
        # create requests for clients
        
        # run these at startup
        exec(open("./brain/logic/ServerStartup.py").read())
        
        # run these forever code -- optimization
        period=open("./brain/logic/Periodical.py").read()
        
        while True:
            # run these forever
            exec(period)


    def _send(self, cmd):
        tmp = self.cmd.getcmd(cmd)
        self.net.send(tmp, tmp["dev"], 5555)
开发者ID:fialakarel,项目名称:haut-server,代码行数:41,代码来源:brain.py

示例4: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import send [as 别名]
# version 0.2

"""
hlavni smycka klienta pro spousteni modulu
"""

import os, sys
from network import Network
from datetime import datetime
from modules import *
from config import *
import threading

net = Network(CLIENT_IP, CLIENT_PORT)

net.send({"key": "status", "value": "login"}, SERVER_IP, SERVER_PORT)

try:
    while True:

        x = ""
        # receive data
        data = net.recv()

        # wrong data, try it again
        if data == False:
            continue

        # variable HACK -- safe check
        try:
            cmd = data["cmd"]
开发者ID:fialakarel,项目名称:haut-client,代码行数:33,代码来源:haut-client.py

示例5: Network

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import send [as 别名]
import sys
from config import *
from network import Network
from brain.cmd import *

udp = Network()

try:
    while True:
        in1 = input("[haut-server] cmd/raw: ")
        if in1 == "cmd":
            for key in cmd:
                print(key)
            in2 = input("[haut-server] CMD: ")
            try:
                udp.send(cmd[in2], "127.0.0.1", 5555)
            except:
                print("ERR")
            continue

        elif in1 == "raw":
            d = dict()
            d["cmd"] = input("[haut-server] CMD: ")
            d["arg"] = input("[haut-server] ARG: ")
            while True:
                other = input("[haut-server] other [y/n]: ")
                if other == "y":
                    key1 = input("[haut-server] KEY: ")
                    d[key1] = input("[haut-server] VALUE: ")
                elif other == "n":
                    break
开发者ID:fialakarel,项目名称:haut-server,代码行数:33,代码来源:haut-control.py

示例6: Irc

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import send [as 别名]
class Irc(Greenlet):
    """
        irc connection abstraction. inherits:
        start(), join(), kill(exception=GreenletExit, block=False, timeout=None), ready(), successful(), etc
        __init__ only receives:
            tag:        "myfreenode",
            fd:         2 or None

        the other options are accessed through the following properties,
        which delegate calls to conf.get:
            servers:    [Server("server.address +1234"), ...],
            encoding:   "utf-8"
            network:    "freenode",
            nick:       "sqrl",
            username:   "sqrl",
            password:   "server password",
            nickservpassword: "nisckerv password",
            realname:   "real name",
            chans:      ["#channel": {"blacklist": ["ex"]}, ...],
            scripts:    ["users", "seen", "com", "version", "wik", "title", "choice", "dic", "ex", ...],
            masters:    ["*!*@unaffiliated/squirrel", ...]
    """

    def __init__(self, tag, fd=None, me=None):
        super(Irc, self).__init__()
        self.tag = tag
        self.net = Network(fd)
        self.group = Group()
        self.logger = logging.getLogger(self.tag)
        self.logger.setLevel(1)
        self.formatter = CuteFormatter(maxbytes=400, encoding=self.encoding)
        self.connected = fd is not None
        if self.connected:
            self.me = me
        else:
            self.me = (self.nick, None, None)

    def __repr__(self):
        return u"Irc(tag=%s)" % self.tag

    ############################################################################################### core

    def _run(self):
        """
            greenlet starts here
            connect to irc, serve in a loop
            run self.disconnect() and self.onunload() on GreenletExit and die
        """
        self.onload()                               # let it fail
        try:
            while True:
                if not self.connected:
                    self.connect()                  # let it fail (should not happen, relly)
                    for chan in self.chans:
                        self.joinchan(chan)
                while True:
                    try:
                        line = self.net.getline()
                        line = line.decode(self.encoding)
                        try:
                            msg = Message(irc=self, line=line)
                        except MessageMalformed as e:
                            self.onexception(e, unexpected=True)
                            continue
                        self.onmessage(msg)
                        if type(msg) == Message and msg.command == "ping":
                            self.send("PONG %s" % msg.params[0])
                        elif type(msg) == Numeric and msg.num == 1:
                            self.me = (msg.target, None, None)
                            self.onconnected(msg)
                            self.privmsg(msg.target, "id")
                        elif msg.frommyself:
                            self.me = msg.sender
                            self.formatter.maxbytes = 512 - 7 - len("".join(self.me).encode(self.encoding))    # :[email protected] <PRIVMSG :text>+\r\n"
                            self.logger.log(OTHER, "i am {0[0]}!{0[1]}@{0[2]} and i can send {1} bytes".format(self.me, self.formatter.maxbytes))
                    except ConnectionFailed as e:
                        self.onexception(e, unexpected=True)
                        self.disconnect()
                        break
                    except GreenletRehash:          # don't disconnect
                        raise
                    except GreenletExit:            # same as above, but disconnect
                        self.disconnect()           # let it fail (should not happen, relly)
                        raise
                    except Exception as e:
                        self.onexception(e, unexpected=True)
        finally:
            self.onunload()                         # let it fail

    def shutdown(self, exception=GreenletExit):
        """
            kills sender greenlet, all greenlets in group, oneself
            this will cause _run to exit and the thing should get deleted from memory
            ! if exception is GreenletExit, disconnects
        """
        self.group.kill(exception, block=False)
        self.kill(exception, block=False)

    ############################################################################################### my cute methods

#.........这里部分代码省略.........
开发者ID:oakkitten,项目名称:sqrl3,代码行数:103,代码来源:irc.py


注:本文中的network.Network.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。