def run(self): app = Application() path = '/tmp/%s' % self.name if os.path.exists(path): os.remove(path) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.bind(path) s.listen(1) sockets = [s.fileno()] while self.running: r, w, e = select.select(sockets, [], [], 10) if len(r) == 0: continue if s.fileno() in r: conn, addr = s.accept() self.clients.append(Socket(conn)) sockets.append(conn.fileno()) for conn in self.clients: if conn.fileno() in r: d = conn.read() if conn.connected: app.queue(self.cb, conn, d) else: sockets.remove(conn.fileno()) self.clients[:] = [x for x in self.clients if x.connected] s.close()
def create(self, gateType, mouseCords, screen): self.screen = screen self.type = gateType self.image, self.rect = load_image( os.getcwd() + "/" + gateType + '.png', -1) print(self.type, " created, cords: ", self.rect.topleft) self.setCords(mouseCords[0], mouseCords[1]) if gateType == "not": # for a not gate, we only create one input socket. socket1 = Socket() socket1.setType("in") socket1.setGate(self) socket1.setIndex(0) socket1.setScreen(self.screen) socket1.update() self.inSockets.append(socket1) outSocket = Socket() outSocket.setType("out") outSocket.setGate(self) outSocket.setScreen(self.screen) outSocket.update() self.outSocket = outSocket else: # otherwise: two inputs, one output. socket1 = Socket() socket1.setType("in") socket1.setGate(self) socket1.setIndex(0) socket1.setScreen(self.screen) socket1.update() self.inSockets.append(socket1) socket2 = Socket() socket2.setType("in") socket2.setGate(self) socket2.setIndex(1) socket2.setScreen(self.screen) socket2.update() self.inSockets.append(socket2) outSocket = Socket() outSocket.setType("out") outSocket.setGate(self) outSocket.setScreen(self.screen) outSocket.update() self.outSocket = outSocket
def __init__(self, loop, socket, peeraddr): self.loop_ = loop self.socket_ = Socket(socket) self.peeraddr_ = peeraddr self.events_ = Events(self.socket_.getSocketFd(), kEevntRead) self.handle_ = Handle(self.events_) self.recvBuffer_ = '' self.writeBuffer_ = '' self.messageCb_ = defMessageCallback
def __init__(self, loop): self.loop_ = loop self.serversd_ = Socket() self.serversd_.bind() self.serversd_.listen(100) self.conns_ = {} self.events_ = Events(self.serversd_.getSocketFd(), kEevntRead) self.handle_ = Handle(self.events_, self.serverReadCb) self.loop_.addHandle(self.handle_) self.messageCb_ = defMessageCallback
def create(self, gateType, mouseCords, screen): self.screen = screen self.type = gateType self.image, self.rect = load_image(os.getcwd()+"/bulb0.png", -1) print(self.type, " created, cords: ", self.rect.topleft) self.setCords(mouseCords[0], mouseCords[1]) socket = Socket() socket.setType("in") socket.setGate(self) socket.setIndex(0) socket.setScreen(self.screen) socket.update() self.inSockets.append(socket)
def create(self, gateType, mouseCords, screen): self.screen = screen self.type = gateType self.image, self.rect = load_image(os.getcwd()+"/switch0.bmp", -1) print("switch created, cords: ", self.rect.topleft) self.setCords(mouseCords[0], mouseCords[1]) outSocket = Socket() outSocket.setType("out") outSocket.setGate(self) outSocket.setScreen(self.screen) outSocket.update() self.outSocket = outSocket print("switch created at ", mouseCords, " with outSocket at ", outSocket.rect.topleft)
def open(self): """ Initializes connection :return: """ # Initialize the port if not self.conn: try: self.conn = Socket(port=self.port, baudrate=self.baudrate) self.conn.conn.open() except OSError as e: raise SonarNotFound(self.port, e) rospy.loginfo("Initializing connection with depth board on %s", self.port) self.initialized = True
def open(self): """ Initializes sonar connection :return: """ # Initialize the port if not self.conn: try: self.conn = Socket(self.port, self.baudrate) except OSError as e: raise SonarNotFound(self.port, e) rospy.loginfo("Initializing connection with firing mechanism on %s", self.port) self.initialized = True self.read()
def expand(self): import stat from BlockDevice import BlockDevice from CharacterDevice import CharacterDevice from File import File from Link import Link from NamedPipe import NamedPipe from Socket import Socket subdirectories = [] import os children = os.listdir(self.fullname()) for name in children: if self._children.has_key(name): continue pathname = os.path.join(self.fullname(), name) # PORTABILITY: lstat is unix only mode = os.lstat(pathname)[stat.ST_MODE] if stat.S_ISDIR(mode): node = Directory(name, self) subdirectories.append(node) elif stat.S_ISREG(mode): node = File(name, self) elif stat.S_ISLNK(mode): node = Link(name, self) elif stat.S_ISSOCK(mode): node = Socket(name, self) elif stat.S_ISFIFO(mode): node = NamedPipe(name, self) elif stat.S_ISCHR(mode): node = CharacterDevice(name, self) elif stat.S_ISBLK(mode): node = BlockDevice(name, self) else: Firewall.hit("unknown file type: mode=%x" % mode) self._children[node.name] = node self._subdirectories = subdirectories return subdirectories
def main(): print("SysBot Corrupter " + ver + " by rydoginator") config = configparser.ConfigParser() if os.path.isfile('config.ini'): config.read('config.ini') ip = config['Server']['host'] port = config['Server']['port'] if not config['Misc'].getboolean('SkipMsg'): if BoolInput("Would you like to connect to " + ip + ":" + port + "? y or n:"): if BoolInput("Would you like to skip this message in the future? y or n:"): config['Misc']['SkipMsg'] = 'yes' else: config['Misc']['SkipMsg'] = 'no' else: ip = input("Enter switch IP address:") else: ip = input("Enter switch IP address:") s = Socket() s.connect(ip, PORT) if s.connected: if not config['Misc'].getboolean('SkipMsg'): if BoolInput("Would you like to skip this message in the future? y or n:"): config['Misc']['SkipMsg'] = 'yes' else: config['Misc']['SkipMsg'] = 'no' config['Server']['host'] = ip config['Server']['port'] = str(PORT) with open('config.ini', 'w') as f: config.write(f) print("Press Ctrl+C to stop execution") print("Executing in...") for x in range(0,3): print(3 - x) time.sleep(1) offset = 0 while True: value = s.readFloat(x * 4 + 0x0) if between(value, 1.0, 2.0): buf = struct.pack("f", value) print (offset + "->" + buf) print (str(offset) + "->" + str(value)) offset = offset + 4
def __init__(self, c_instance): super(AbletonJS, self).__init__(c_instance) Socket.set_log(self.log_message) Socket.set_message(self.show_message) self.socket = Socket(self.command_handler) self.handlers = { "internal": Internal(c_instance, self.socket), "cue-point": CuePoint(c_instance, self.socket), "device": Device(c_instance, self.socket), "device-parameter": DeviceParameter(c_instance, self.socket), "scene": Scene(c_instance, self.socket), "song": Song(c_instance, self.socket), "song-view": SongView(c_instance, self.socket), "track": Track(c_instance, self.socket), "clip_slot": ClipSlot(c_instance, self.socket), } self.parse() self.socket.send("connect")
def __init__(self): self.mouse = [] super().__init__() self.title() super().geometry("%dx%d+105+105" %(self.WIDTH, self.HEIGHT)) super().configure(bg = self.BACKGROUND) super().title(self.TITLE) super().maxsize(self.WIDTH, self.HEIGHT) super().minsize(self.WIDTH, self.HEIGHT) super().bind("<Button-1>", self.click) ### catchup the event of mouse clicked self.cv = XCanvas(root = self) #### initital Canvas self.debug = Debug(root = self, cord = self.FENS["comment"]) self.db = Database() self.btnCommOn = False ### communication status with RaspBerryPi, TRUE or FALSE self.btnGpioOn = True ### SIGNAL LEVEL (On or Off) to GPIO self.sock = Socket(callback = self.getResult) self.network = self.db.loadImage(file = "network") self.switch = self.db.loadImages(files = ["swOff", "swOn"])
user = raw_input("user ") passwd = getpass("password ") server_url = "http%s://%s:%s@%s:%s/" % ("", user, passwd, "127.0.0.1", 7227) proxy = xmlrpclib.ServerProxy(server_url, allow_none=True) bench(proxy.get_server_version) bench(proxy.status_server) bench(proxy.status_downloads) #bench(proxy.get_queue) #bench(proxy.get_collector) print try: # Make socket transport = Socket('localhost', 7228, False) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = Protocol(transport) # Create a client to use the protocol encoder client = Pyload.Client(protocol) # Connect! transport.open() print "Login", client.login(user, passwd)
def expand(self): import os import stat from BlockDevice import BlockDevice from CharacterDevice import CharacterDevice from File import File from Link import Link from NamedPipe import NamedPipe from Socket import Socket import journal debug = journal.debug("pyre.filesystem") files = [] subdirectories = [] self._children = {} root = self.path children = os.listdir(root) debug.log("directory '%s' has %d files" % (self.name, len(children))) count = 0 for name in children: count += 1 if name in self._children: continue pathname = os.path.join(root, name) # PORTABILITY: lstat is unix only mode = os.lstat(pathname)[stat.ST_MODE] if stat.S_ISDIR(mode): node = Directory(name, self) subdirectories.append(node) elif stat.S_ISREG(mode): node = File(name, self) files.append(node) elif stat.S_ISLNK(mode): node = Link(name, self) elif stat.S_ISSOCK(mode): node = Socket(name, self) elif stat.S_ISFIFO(mode): node = NamedPipe(name, self) elif stat.S_ISCHR(mode): node = CharacterDevice(name, self) elif stat.S_ISBLK(mode): node = BlockDevice(name, self) else: Firewall.hit("unknown file type: mode=%x" % mode) self._children[node.name] = node if not count % 1000: debug.log("processed %d files" % count) debug.log("total files processed: %d" % count) self._files = files self._subdirectories = subdirectories return subdirectories
from Socket import Socket from GetSensor import getSensor from cm01module import Cm01Module socket = Socket("http://localhost:3000") get_sensor = getSensor(socket) cm01module = Cm01Module(socket, get_sensor)
def __init__(self, host, port, login, password): self._Socket = Socket(host, port) self.Host = host self.Port = int(port) self.Login = login self.Password = password
from flask import Flask, render_template, json, request import pdb import os from Socket import Socket, ETHERNET_IP, WIFI_IP app = Flask(__name__, static_url_path='') S = Socket(ip="192.168.1.13") @app.route('/<path:path>/css') def send_js(path): return send_from_directory('css', path) @app.route('/<path:path>/js') def send_css(path): return send_from_directory('js', path) @app.route('/hello') def hello_world(): return 'hello world' @app.route('/') def main(): return render_template('index.html') @app.route('/data', methods=['POST'])
#### WHAT THE SCRIPT IS DOING: # one port,one main thread # if it receives "i wanna play" then it starts a new thread listenForNewTTTPlayers # to create a game # this thread runs a function that just keeps waiting until the main thread notifies it to take the other player from Socket import Socket import threading, random, json, Queue from Games import Games sock = Socket(5005) games = Games(sock) #global games object newPlaysLock = threading.Lock() newPlaysCV = threading.Condition(newPlaysLock) newPlaysQ = Queue.Queue( ) #a queue of dicts {username:username,addressPortTuple:addressportTuple} def listenForNewPlays(): #{ """ listenForNewPlayers: accepts no parameters creates one "Games" object while True: keep waiting for something to appear on the newplaysQ take it from the queue and leave it to the games.play() method """ while True: #{ with newPlaysCV: #{
def __init__(self): self.socket = Socket()
if data < 0: dataType = 's' #in the case of 'w' datatype, a negative value will indicate 's' for backwards data = int(interp(abs(data), [0, 100], [40, 255])) #make sure data has 3 digits if (data < 10): data = "00" + str(data) elif (data < 100): data = "0" + str(data) else: data = str(data) toSend = str(data) + str(dataType) print(toSend) connection.send((toSend).encode('utf-8')) if __name__ == "__main__": socketInstance = Socket(WINDOWS_HOST, RASPBERRY_PORT) print("Listening...") connection, address = socketInstance.startListening() print(f"Connection from: {str(address)}") app = App(connection) #Wait for GUI thread to initialize the GUI elements, before receiving data. #Otherwise, lblPotent object does not exist so its text cannot be changed. sleep(1) while 1: data = connection.recv(BAUD_RATE).decode('utf-8', 'ignore') #print(data) if not data: exit() print(f"From raspberry pi: {data}") app.lblPotent.config(text=f"Potent Value: {data}")
logging.info('Video server will be stopped ("exit" message got)') client.close() stopped = True break else: logging.warning('Unknown request method "' + request + '" : connection closed') client.close() break logging.debug('Conection with client closed: addr=' + clientaddr) exit(0) logging.info('Video server has been started') server = Socket() server.bind(('127.0.0.1', 4242)) server.listen(5) camera = cv2.VideoCapture(0) while not stopped: connection = server.tryaccept(3) if connection is None: continue client, addr = connection thread = threading.Thread(target=processConnection, args=(client, camera)) thread.start() #for thread in threading.enumerate() : # if thread != threading.currentThread() :
Its parameters are: -a --address followed by the servers's IP address. This parameter must be specified. -p --port followed by the server's port. Default is 1337 for both client and server. -h --help displays this message. """ parser = optparse.OptionParser() parser.add_option( "-a", "--address", action="store", dest="address", help= "This option is obligatory and must be equivalent to the server's IP address." ) parser.add_option( "-p", "--port", action="store", dest="port", default=1337, type=int, help= "This option's value must correspond to the server's port. By default, it's 1337 for both client and server." ) opts = parser.parse_args(sys.argv[1:])[0] if opts.address == None: print("Use -h --help to get help.") else: interface_utilisateur = Client(Socket(opts.address, opts.port))