def do_send_message(self, sock, tid, message=None, echo_msg=None): # for sid, client_sock in JBServer.client_dict.iteritems(): # if client_sock is not sock: # if message is not None: # client_sock.sendall(comm.pack_data(tid, message)) if echo_msg is not None: sock.sendall(comm.pack_data(tid, echo_msg)) for pairsock in sock.teams: pairsock.sendall(comm.pack_data(tid, message))
def you_recv(s): while 1: if int(time.time()) % 10 == 0: protocol.C2S_HEARTBEAT.data = int(time.time()) p = comm.copy_protocol('C2S_HEARTBEAT') p.set_data(int(time.time())) s.sendall(comm.pack_data(p.type_, p.data)) print '------------' r, w, x = select.select([s, sys.stdin], [], []) for rr in r: if rr is s: header_reply = rr.recv(4) if header_reply: type_, len_ = comm.struct_unpack(header_reply) content_reply = rr.recv(len_) content_reply = comm.unpack_data(content_reply) print type_ print protocol.S2C_VERSION.type_ if protocol.S2C_VERSION.eq(type_): print 'Version right!!' elif protocol.ERR_VERSION.eq(type_): print 'Version wrong!!' elif protocol.S2C_HEARTBEAT.eq(type_): print 'heartbeating ...' elif protocol.S2C_LOGIN.eq(type_): print 'S2C_LOGIN ...' # print "type = %s, content=%s" % (type_, content_reply) else: msg = rr.readline() protocol.C2S_VERSION.data = '0.0.1' p = comm.copy_protocol('C2S_LOGIN') p.set_data(json.dumps({'name': 'daimin2', 'passwd': '123'})) s.sendall(comm.pack_data(p.type_, p.data)) gevent.sleep(0)