File: bbs_client_socket.py

package info (click to toggle)
mongrel2 1.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,976 kB
  • sloc: ansic: 39,083; python: 2,833; sql: 1,555; sh: 467; makefile: 360; asm: 189; yacc: 145; php: 73; awk: 28; sed: 5
file content (17 lines) | stat: -rw-r--r-- 332 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CONN = socket.socket()
CONN.connect((host, port))

def read_msg():
    reply = ""

    ch = CONN.recv(1)
    while ch != '\0':
        reply += ch
        ch = CONN.recv(1)

    return json.loads(b64decode(reply))

def post_msg(data):
    msg = '@bbs %s\x00' % (
        json.dumps({'type': 'msg', 'msg': data}))
    CONN.send(msg)