Example #1
0
	def get_user_info(self):
		obj={}
		obj['uid']=self.uid
		data=json.dumps(obj)
		send_packet(self.con,self.uid,9,data,len(data));
		command,content,content_len=rcv_packet(self.con)
		
		if content_len == -1:
			print 'connect server error.'
			return -1
		else:
			content_json=json.loads(content)
			return content_json		
Example #2
0
	def send_msg_to_friend(self,con,uid,fid,msg):
		obj={}
		obj['uid']=uid
		obj['fid']=fid
		obj['msg']=msg
		data=json.dumps(obj)
		send_packet(con,uid,20,data,len(data));
		command,content,content_len=rcv_packet(con)
		print content
		if content_len == -1:
			print 'connect server error.'
			return 0
		else:
			content_json=json.loads(content)
			print content_json
Example #3
0
def friend_list_request(con,uid):
	obj={}
	obj['uid']=uid
	data=json.dumps(obj)
	send_packet(con,uid,3,data,len(data));
	command,content,content_len=rcv_packet(con)
	print content
	if content_len == -1:
		print 'connect server error.'
		return 0
	if command!=3 or len(content)==0:
		return 0
	else:
		content_json=json.loads(content)
		print content_json
Example #4
0
	def update_friend_list(self):
		obj={}
		obj['uid']=self.uid
		self.friend_list=[]
		data=json.dumps(obj)
		send_packet(self.con,self.uid,3,data,len(data));
		command,content,content_len=rcv_packet(self.con)
		
		if content_len == -1:
			print 'connect server error.'
			return -1
		else:
			content_json=json.loads(content)
			self.friend_num=content_json['friend_num']
			for f in content_json['list']:
				friend=Friend(f['loginid'],f['nickname'],f['address'],f['phone_num'],
				f['sex'],f['signature'],f['mail'],f['online'],f['age'])
				self.friend_list.append(friend);
			return content_json
Example #5
0
def get_user_image(con,uid):
	obj={}
	obj['uid']=uid
	data=json.dumps(obj)
	send_packet(con,uid,7,data,len(data));
	command,content,content_len=rcv_packet(con)

	if content_len == -1:
		print 'connect server error.'
		return 0
		
	if command !=8 or len(content)==0:
		return 0
	else:
		content_json=json.loads(content)
		decoded_img_data=base64.b64decode(content_json['img'])
		#for debug
		fd = open("clients/%d.png"%uid,"wb")
		fd.write(decoded_img_data)
		fd.close()
		return decoded_img_data;
Example #6
0
	def login(self):
		obj={}
		obj['username']=self.uid
		obj['password']=self.password
		data=json.dumps(obj)
		send_packet(self.con,self.uid,1,data,len(data));
		command,content,content_len=rcv_packet(self.con)
		print content
		if content_len == -1:
			print 'connect server error.'
			return 0
		if  len(content)==0:
			return 0
		else:
			content_json=json.loads(content)
			
			if content_json['login_status'] == 'success':
				print 'login success........'
				return 1
			else:
				print 'login fail.............'
				return 0
Example #7
0
def upload_user_image(con,uid):
	obj={}
	obj['uid']=uid
	fd=open("111.png","rb")
	img_data=fd.read()
	encoded_img_data=base64.b64encode(img_data)
	obj['img']=encoded_img_data

	fd.close()

	data=json.dumps(obj)
	print data
	send_packet(con,uid,5,data,len(data));
	command,content,content_len=rcv_packet(con)
	print content
	if content_len == -1:
		print 'connect server error.'
		return 0
	if command != 6 or len(content)==0:
		print 'command error'
		return 0
	else:
		content_json=json.loads(content)
		print content_json