ChatClient.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:high-quality-chat 作者: b6938236 项目源码 文件源码
def send_file(self, filepath):
        """
        Send a base64 encoded string to the server.
        :param filepath: string path to file
        :return: None
        """
        _, tail = os.path.split(filepath)
        print str(self.username) + " sending out " + str(tail)
        fh = open(filepath, 'rb')
        content = base64.b64encode(fh.read())
        payload = self.new_payload()
        payload['content'] = content
        payload['type'] = constants.FILE
        payload['filename'] = os.path.basename(filepath)
        # Send the payload as a binary message by marking binary=True
        self.send(str(json.dumps(payload)), True)
        # Avoid feedback
        time.sleep(0.2)
        fh.close()
        # self.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号