• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python socket.makefile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中socket.makefile函数的典型用法代码示例。如果您正苦于以下问题:Python makefile函数的具体用法?Python makefile怎么用?Python makefile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: client_protocol

def client_protocol(socket):
    connect_write_to_server = socket.makefile('w')
    protocol = 'I32CFP_HELLO\n'
    connect_write_to_server.write(protocol)
    connect_write_to_server.flush()
    receive_ready = socket.makefile('r')
    protocol = receive_ready.readline()
    if protocol == 'READY\n':
        print('The server is ready to start the game')
        pass
    else:
        socket.close()
        print('server not speaking the same protocols,close connection.\n')
        return 
开发者ID:409230250,项目名称:Programming-with-Software-Libraries-on-Python,代码行数:14,代码来源:Lab2_Console+Only.py


示例2: handle_request

	def handle_request(socket, client_address, server):
		s = ServerInfo(software=server_version, multiconnection=True, multithread=False, multiprocess=False)
		c = ConnectionInfo(server=s)

		c.server.addr = LazyAddress(socket.family, lambda: socket.getsockname())
		c.remote.addr = Address(socket.family, client_address)

		c.socket = socket

		with socket.makefile('r') as input:
			with socket.makefile('w') as output:
				app(input, output, sys.stderr, c)
开发者ID:LEW21,项目名称:reserve,代码行数:12,代码来源:server.py


示例3: receive_protocols

def receive_protocols(socket):
    file_in = socket.makefile('r')
    protocols = file_in.readline()
    file_in.close()
    if protocols == 'I32CFP_HELLO\n':
        file_out = socket.makefile('w')
        file_out.write('READY\n')
        file_out.flush()
        file_out.close()
        pass
    else:
        socket.close()
        print('Client is not speaking the same protocols.Closing connection.\n')
        return 
开发者ID:409230250,项目名称:Programming-with-Software-Libraries-on-Python,代码行数:14,代码来源:Lab2_Console+Only.py


示例4: handle

 def handle(self, socket, address):
     """
     If not a leader, a node will simply return a single item list pointing
     to the leader. Otherwise, it will add the host of the connected client
     to the cluster roster, broadcast to all nodes the new roster, and wait
     for keepalives. If no keepalive within timeout or the client drops, it
     drops it from the roster and broadcasts to all remaining nodes. 
     """
     self.logger.debug('New connection from %s:%s' % address)
     if not self.manager.is_leader:
         socket.send(json.dumps({'leader': self.manager.client.leader_address[0], 
             'port': self.manager.client.leader_address[1]}))
         socket.close()
         self.logger.debug("Redirected to %s:%s" % self.manager.client.leader_address)
     else:
         socket.send(self._cluster_message())
         sockfile = socket.makefile()
         name = sockfile.readline()
         if not name:
             return
         if name == '\n':
             name = address[0]
         else:
             name = name.strip()
         self._update(add={'host': name, 'socket': socket})
         # TODO: Use TCP keepalives
         timeout = self._client_timeout(socket)
         for line in util.line_protocol(sockfile, strip=False):
             timeout.kill()
             timeout = self._client_timeout(socket)
             socket.send('\n')
             self.logger.debug("Keepalive from %s:%s" % address)
         self.logger.debug("Client disconnected from %s:%s" % address)
         self._update(remove=name)
开发者ID:haridas,项目名称:gevent-tools,代码行数:34,代码来源:cluster.py


示例5: wait_server_move

def wait_server_move(mode,column,socket):
    output = socket.makefile('w')
    output.write(mode+ ' ' + str(column)+'\n')
    output.flush()
    output.close()
    print('Waiting for server to move or update.')
    pass
开发者ID:409230250,项目名称:Programming-with-Software-Libraries-on-Python,代码行数:7,代码来源:Project#2(new).py


示例6: __init__

 def __init__(self, server, socket):
     self.server = server
     self.socket = socket
     self.socket_file = socket.makefile('rb', 0)
     self.compression_enabled = False
     self.user_uuid = None
     self.user_name = None
开发者ID:ammaraskar,项目名称:pyCraft,代码行数:7,代码来源:fake_server.py


示例7: listen_on_socket

def listen_on_socket(socket, *args):
    if socket is None:
        return
    command = ""
    file = socket.makefile('rwb')
    while True:
        try:
            data = file.read(1)
            if data == b'':
                sleep(0.001)
                continue
            else:
                data = data.decode('ascii')
            if data == AtHomeProtocol['end_of_communication']:
                print('Communication ended', file=sys.stderr)
                return
            if data != AtHomeProtocol['end_of_command']:
                command += data
            else:
                command = ""
                continue
            if command.endswith(AtHomeProtocol['end_of_line']):
                command = command[0:-2]
                if command in AtHomeCommands:
                    AtHomeCommands[command](file)
                else:
                    command = ""
                    raise NameError('[Unknown Command] %s' % command)
                command = ""
        except EOFError:
            file.close()
            socket.close()
            return
        except Exception as e:
            print('[Exception] %s' % e, file=sys.stderr)
开发者ID:AtHomeEIP,项目名称:middleware,代码行数:35,代码来源:SocketMiddleware.py


示例8: __init__

 def __init__(self, socket):
     """Keeps track of the socket and the file posing as the socket"""
     self.socket = socket
     self.stream = socket.makefile()
     self.active = True
     self.editor = 'Emacs'
     self.name = 'Richard Stallman'
开发者ID:ebanner,项目名称:TextEditorTournament,代码行数:7,代码来源:participant.py


示例9: mangodb

def mangodb(socket, address):
    socket.sendall('HELLO\r\n')
    client = socket.makefile()
    output = open(os.devnull, 'w')
    lock = threading.Lock()
    wait = threading.Condition(lock)
    while 1:
        line = client.readline()
        if not line:
            break
        cmd_bits = line.split(' ', 1)
        cmd = cmd_bits[0]
        if cmd == 'BYE':
            break
        if cmd == 'WAIT':
            wait.wait()
            continue
        if len(cmd_bits) > 1:
            lock.acquire(True)
            output.write(cmd_bits[1])
            if MANGODB_DURABLE:
                output.flush()
                os.fsync(output.fileno())
            data = '42' if MANGODB_EVENTUAL else \
                os.urandom(1024).encode('string-escape')
            lock.release()
            client.write('OK' + data + '\r\n')
        client.flush()
开发者ID:eklitzke,项目名称:mangodb,代码行数:28,代码来源:server.py


示例10: WrapAndSendPayload

    def WrapAndSendPayload(cls, socket, payload):
        '''
        Send payload, true if success, false if failed
        '''
        try:
            # From SocketServer.py
            # wbufsize = 0, flush immediately
            wbufsize = -1
            # Convert
            socket_message = SocketMessage(payload)
            wfile = socket.makefile('wb', wbufsize)
            # Write the message
            wfile.write(struct.pack(fmt, socket_message.magic))
            # Need to send the packed version
            # print 'Sent ', socket_message.magic

            wfile.write(struct.pack(fmt, socket_message.payload_size))
            # print 'Sent ', socket_message.payload_size

            wfile.write(payload)
            # print 'Sent ', payload
            wfile.flush()
            wfile.close() # Close file object, not close the socket
            return True
        except Exception as e:
            _L.error('Fail to send message %s', e)
            return False
开发者ID:Batname,项目名称:unrealcv,代码行数:27,代码来源:__init__.py


示例11: run

    def run(self):
        """Starts listening and accepting connection requests.

           This method is called when invoking `CallbackServer.start()`. A
           CallbackServer instance is created and started automatically when
           a :class:`JavaGateway <py4j.java_gateway.JavaGateway>` instance is
           created.
        """
        try:
            with self.lock:
                self.is_shutdown = False
            logger.info('Callback Server Starting')
            self.server_socket.listen(5)
            logger.info('Socket listening on {0}'.
                    format(smart_decode(self.server_socket.getsockname())))

            while not self.is_shutdown:
                socket, _ = self.server_socket.accept()
                input = socket.makefile('rb', 0)
                connection = CallbackConnection(self.pool, input, socket,
                        self.gateway_client)
                with self.lock:
                    if not self.is_shutdown:
                        self.connections.append(connection)
                        connection.start()
                    else:
                        connection.socket.shutdown(socket.SHUT_RDWR)
                        connection.socket.close()
        except Exception:
            if self.is_shutdown:
                logger.info('Error while waiting for a connection.')
            else:
                logger.exception('Error while waiting for a connection.')
开发者ID:gdw2,项目名称:py4j,代码行数:33,代码来源:java_gateway.py


示例12: wait_player_move

def wait_player_move(mode, col,socket):
    output = socket.makefile('w')
    output.write(mode+ ' ' + str(col)+'\n')
    output.flush()
    output.close()
    print('waiting for player to move')
    pass
开发者ID:409230250,项目名称:Programming-with-Software-Libraries-on-Python,代码行数:7,代码来源:Lab2_Console+Only.py


示例13: __init__

    def __init__(self, server, socket):
        """
Override BaseHTTPRequestHandler.__init__(): we need to be able
to have (potentially) multiple handler objects at a given time.

Inputs:
    server  -- server object to handle requests for 
    socket  -- socket connection 
        """

        ## Settings required by BaseHTTPRequestHandler
        self.rfile = socket.makefile("rb", -1)
        self.wfile = socket.makefile("wb", 0)
        self.connection = socket
        self.client_address = (server.host, server.port)

        self._server = server
开发者ID:mash0304,项目名称:pathos,代码行数:17,代码来源:server.py


示例14: wait_server_move

def wait_server_move(mode,drop,socket):
    print('runing wait server move')
    output = socket.makefile('w')
    output.write(mode+ ' ' + str(drop)+'\n')
    output.flush()
    output.close()
    print('waiting for server to move')
    pass
开发者ID:409230250,项目名称:Programming-with-Software-Libraries-on-Python,代码行数:8,代码来源:Lab2_Console+Only.py


示例15: run

 def run(self, room, program, password):
     socket = self.connect_to_service()
     socket_fd = socket.makefile()
     skip_hello(socket_fd)
     send("run", socket)
     send(password, socket)
     send(room, socket)
     send(program, socket)
     return readline(socket_fd)
开发者ID:HackerDom,项目名称:ructf-2016,代码行数:9,代码来源:cleaner.exploit2.py


示例16: get_room

 def get_room(self, room, password):
     socket = self.connect_to_service()
     socket_fd = socket.makefile()
     skip_hello(socket_fd)
     send("get_room", socket)
     send(password, socket)
     send(room, socket)
     line = readline(socket_fd)
     return line
开发者ID:HackerDom,项目名称:ructf-2016,代码行数:9,代码来源:cleaner.checker.py


示例17: get

	def get(self, flag_id, flag):
		socket = self.connect_to_checker()
		socket_fd = socket.makefile()
		send("get " + self.hostname + ":" + str(PORT) + " " + flag_id, socket)
		result = readline(socket_fd)
		if result == flag:
			service_ok()
		else:
			service_corrupt(message="Unexpected GET response: " + result)
开发者ID:HackerDom,项目名称:ructf-2016,代码行数:9,代码来源:bluemesh.checker.py


示例18: recv_lines

def recv_lines(socket):
    lines = []
    file = socket.makefile()
    while True:
        line = file.readline().strip()
        if line == "":
            break
        lines.append(line)
    return lines
开发者ID:0x0mar,项目名称:nogotofail,代码行数:9,代码来源:app_blame.py


示例19: recv_json

def recv_json(socket):
    if not hasattr(recv_json, 'files'):
        recv_json.files = {} # static variable

    if not socket in recv_json.files:
        recv_json.files[socket] = socket.makefile()

    data = recv_json.files[socket].readline()
    return json.loads(data.strip())
开发者ID:arthaud,项目名称:whitenight-server,代码行数:9,代码来源:server.py


示例20: __init__

 def __init__(self, threadID, name, counter,state,socket,finishEvent):
     threading.Thread.__init__(self)
     self.threadID = threadID
     self.name = name
     self.counter = counter
     self.state=state
     self.socket=socket
     self.socket_file=socket.makefile()
     self.finished=finishEvent
开发者ID:aeflores,项目名称:quadcopter,代码行数:9,代码来源:quad_web_communication.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python socket.ntohl函数代码示例发布时间:2022-05-27
下一篇:
Python socket.listen函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap