mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 22:32:21 +03:00
receiver and sender fixed for file transfering
This commit is contained in:
parent
eb4ee5009b
commit
7ef39c3fd3
2 changed files with 15 additions and 7 deletions
|
@ -47,7 +47,7 @@ class MessageReceiver(slixmpp.ClientXMPP):
|
||||||
if self.configurationManager.get('CONNECTION', 'uid') == "" or self.configurationManager.get('CONNECTION', 'uid') is None:
|
if self.configurationManager.get('CONNECTION', 'uid') == "" or self.configurationManager.get('CONNECTION', 'uid') is None:
|
||||||
return str(self.configurationManager.get('CONNECTION', 'host')) #is user want to create connection as anonymous
|
return str(self.configurationManager.get('CONNECTION', 'host')) #is user want to create connection as anonymous
|
||||||
else:
|
else:
|
||||||
return str(self.configurationManager.get('CONNECTION', 'uid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/1793816026658382528511590341137904818696727194330755982493')
|
return str(self.configurationManager.get('CONNECTION', 'uid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/receiver')
|
||||||
|
|
||||||
def get_password(self):
|
def get_password(self):
|
||||||
if self.configurationManager.get('CONNECTION', 'password') == "" or self.configurationManager.get('CONNECTION', 'password') is None:
|
if self.configurationManager.get('CONNECTION', 'password') == "" or self.configurationManager.get('CONNECTION', 'password') is None:
|
||||||
|
@ -68,12 +68,14 @@ class MessageReceiver(slixmpp.ClientXMPP):
|
||||||
|
|
||||||
def stream_opened(self, sid):
|
def stream_opened(self, sid):
|
||||||
print('stream opened')
|
print('stream opened')
|
||||||
#self.logger.info('Stream opened. %s', sid)
|
print('So stream_id:'+str(self.stream_id))
|
||||||
|
|
||||||
self.file = open(self.receive_file_path+self.stream_id, 'wb')
|
self.file = open(self.receive_file_path+self.stream_id, 'wb')
|
||||||
return self.file
|
return self.file
|
||||||
|
|
||||||
def stream_data(self, data):
|
def stream_data(self, data):
|
||||||
print('stream data')
|
print('stream data')
|
||||||
|
self.logger.info('Sd'+self.get_id())
|
||||||
#self.logger.info('Stream data.')
|
#self.logger.info('Stream data.')
|
||||||
self.file.write(data)
|
self.file.write(data)
|
||||||
|
|
||||||
|
@ -86,6 +88,10 @@ class MessageReceiver(slixmpp.ClientXMPP):
|
||||||
self.get_roster()
|
self.get_roster()
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
|
|
||||||
|
def send_direct_message(self,msg):
|
||||||
|
#need connection control
|
||||||
|
print("sending...\n"+msg)
|
||||||
|
self.send_message(mto=self.receiver,mbody=msg,mtype='normal')
|
||||||
|
|
||||||
def invite_auto_accept(self, inv):
|
def invite_auto_accept(self, inv):
|
||||||
self.room=inv['from']
|
self.room=inv['from']
|
||||||
|
@ -107,12 +113,11 @@ class MessageReceiver(slixmpp.ClientXMPP):
|
||||||
j = json.loads(str(msg['body']))
|
j = json.loads(str(msg['body']))
|
||||||
type =j['type']
|
type =j['type']
|
||||||
print ("event will be fired:"+type)
|
print ("event will be fired:"+type)
|
||||||
self.event_manger.fireEvent(type,str(msg['body']))
|
self.event_manger.fireEvent(type,str(msg['body']).lower())
|
||||||
|
|
||||||
|
|
||||||
def connect_to_server(self):# Connect to the XMPP server and start processing XMPP stanzas.
|
def connect_to_server(self):# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
try:
|
try:
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(self.process())
|
loop.run_until_complete(self.process())
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class MessageSender(slixmpp.ClientXMPP):
|
||||||
if self.configurationManager.get('CONNECTION', 'uid') == "" or self.configurationManager.get('CONNECTION', 'uid') is None:
|
if self.configurationManager.get('CONNECTION', 'uid') == "" or self.configurationManager.get('CONNECTION', 'uid') is None:
|
||||||
return str(self.configurationManager.get('CONNECTION', 'host')) #is user want to create connection as anonymous
|
return str(self.configurationManager.get('CONNECTION', 'host')) #is user want to create connection as anonymous
|
||||||
else:
|
else:
|
||||||
return str(self.configurationManager.get('CONNECTION', 'uid')+'@'+self.configurationManager.get('CONNECTION', 'host'))
|
return str(self.configurationManager.get('CONNECTION', 'uid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/sender')
|
||||||
|
|
||||||
def get_password(self):
|
def get_password(self):
|
||||||
if self.configurationManager.get('CONNECTION', 'password') == "" or self.configurationManager.get('CONNECTION', 'password') is None:
|
if self.configurationManager.get('CONNECTION', 'password') == "" or self.configurationManager.get('CONNECTION', 'password') is None:
|
||||||
|
@ -74,11 +74,13 @@ class MessageSender(slixmpp.ClientXMPP):
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def session_start(self, event):
|
def session_start(self, event):
|
||||||
|
print("session start")
|
||||||
self.get_roster()
|
self.get_roster()
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
|
|
||||||
if self.message is not None:
|
if self.message is not None:
|
||||||
self.send_direct_message(self.message)
|
self.send_direct_message(self.message)
|
||||||
|
print("sent")
|
||||||
|
|
||||||
if self.file is not None:
|
if self.file is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -124,7 +126,7 @@ class MessageSender(slixmpp.ClientXMPP):
|
||||||
def connect_to_server(self):# Connect to the XMPP server and start processing XMPP stanzas.
|
def connect_to_server(self):# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
try:
|
try:
|
||||||
self.connect()
|
self.connect()
|
||||||
self.process(forever=False)
|
self.process(forever=True)
|
||||||
#self.logger.info('Connection were established successfully')
|
#self.logger.info('Connection were established successfully')
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -137,7 +139,8 @@ class MessageSender(slixmpp.ClientXMPP):
|
||||||
self.register_plugin('xep_0030') # Service Discovery
|
self.register_plugin('xep_0030') # Service Discovery
|
||||||
self.register_plugin('xep_0045') # Multi-User Chat
|
self.register_plugin('xep_0045') # Multi-User Chat
|
||||||
self.register_plugin('xep_0199') # XMPP Ping
|
self.register_plugin('xep_0199') # XMPP Ping
|
||||||
self.register_plugin('xep_0065') # SOCKS5 Bytestreams
|
self.register_plugin('xep_0065', {'auto_accept': True}) # SOCKS5 Bytestreams
|
||||||
|
self.register_plugin('xep_0047', {'auto_accept': True}) # In-band Bytestreams
|
||||||
|
|
||||||
#self.logger.info('Extension were registered: xep_0030,xep_0045,xep_0199,xep_0065')
|
#self.logger.info('Extension were registered: xep_0030,xep_0045,xep_0199,xep_0065')
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue